Reputation: 21
I'm currently facing an error using ggplot2. I want to create a barplot with standard error bar using this data frame :
mean se pattern quality
1 54.955357 19.792315 spread good
2 54.506944 18.580981 clumped good
3 29.604167 14.937291 centered good good
5 23.300595 14.336305 spread bad
6 8.371528 5.960366 clumped bad
7 16.364583 11.525207 centered good bad
8 7.062500 11.125915 centered bad bad
I use this formula to create my bar plot :
ggplot(table, aes(x=pattern, y=mean, fill=quality))+
geom_bar(position="dodge")+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se,
width=0.2, position=position_dodge(0.9)))
But when I run it, the window that should have my barplot appears blank and this error message pops up
Don't know how to automatically pick scale for object of type proto/environment. Defaulting to continuous
Error : Aesthetics must either be length one, or the same length as the dataProblems:position_dodge(0.9)
When I try to run it without position=position_dodge(0.9)
a bar plot appears but the bars are between each bar of means and not in the middle.
I've tried several value for dodge
and other things but i'm running out of ideas.
Upvotes: 2
Views: 5684
Reputation: 7832
I got a warning that "stat_identity" (mapping to value, not count) was applied. To prevent that warning, simply add stat="identity"
to the geom.
te <- c("val mean se pattern quality",
"1 54.955357 19.792315 spread good",
"2 54.506944 18.580981 clumped good",
"3 29.604167 14.937291 centered_good good",
"5 23.300595 14.336305 spread bad",
"6 8.371528 5.960366 clumped bad",
"7 16.364583 11.525207 centered_good bad",
"8 7.062500 11.125915 centered_bad bad")
df <- read.table(text=te, header=T)
require(ggplot2)
ggplot(df, aes(x=pattern, y=mean, fill=quality))+
geom_bar(position="dodge", stat="identity")+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=0.2, position=position_dodge(0.9))
Upvotes: 5