Make barplot in ggplot2 with summary statistics

2019-09-03 02:45发布

I have data, similar to that in this question, from which I am directly taking Matthew Lundberg's code as an example.

y = data.frame(Specie=c('A','V','R','P','O'),Number=c(18756,8608,3350,3312,1627))

It is demonstrated how to create a barplot using the barplot command:

barplot(y$Number, names.arg=y$Specie)

How would I do the same thing using ggplot2 or qplot?

The following does not work:

library(ggplot2)
y = data.frame(Specie=c('A','V','R','P','O'),Number=c(18756,8608,3350,3312,1627))
qplot(x=y[,2], y=y[,1],  geom="bar", stat="identify")

What to do?

标签: r plot ggplot2
0条回答
登录 后发表回答