针对以下数据集,
Genre Amount
Comedy 10
Drama 30
Comedy 20
Action 20
Comedy 20
Drama 20
我想构建一个ggplot2线图,其中x轴是Genre
,y轴是所有金额的总和(条件是Genre
)。
我已经尝试了以下内容:
p = ggplot(test, aes(factor(Genre), Gross)) + geom_point()
p = ggplot(test, aes(factor(Genre), Gross)) + geom_line()
p = ggplot(test, aes(factor(Genre), sum(Gross))) + geom_line()
但是没有任何效果。
aes
定义中,似乎可以使用reorder
调用,类似于aes(x=reorder(Genre, Amount, sum), y=Amount))
。但是可能还有更好、更清晰的方法来实现。 - juba