Matt Bannert
Matt Bannert

Reputation: 28264

How to barplot frequencies with ggplot2?

I have a melted dataset containing a column "value" which represent an absolute number which varies with every row of the dataset. I want to display this number in a barchart by country.

p <- ggplot(melted,aes(factor(country),y=as.numeric(value))) + geom_bar() +opts(axis.text.x = theme_text(angle = 90,hjust = 1)) 

all I get is:

Error in pmin(y, 0) : Objekt 'y' not found.

Of course I triple-checked if there was a "value" variable I just can't find what's wrong. If a leave the y=... out I get the observations per country which are the same for every country in my case.

Upvotes: 4

Views: 6497

Answers (1)

JoFrhwld
JoFrhwld

Reputation: 9037

You might need to define the identity statistic in geom_bar().

 ggplot(melted,aes(factor(country),y=as.numeric(value))) + 
        geom_bar(stat = "identity", position = "stack")

Upvotes: 5

Related Questions