Hello.
I have been experiencing similar problems with the ggplot2 bar plot: the error bar moves away from the geom_bar. The error bar does not stay on the center of the geom_bar. I would appreciate receiving any advice one could offer to resolve the issue. My code is shown below:
library(ggplot2)
dodge <- position_dodge (width=1)
p <- ggplot(data = tempdata,
aes(x = age, y = est, fill = spd)) +
geom_bar(position=dodge, width=0.50) +
geom_errorbar( aes(ymax = est+se, ymin = est), width=.25, position =dodge)+
scale_fill_manual(values=c("#996633","black"))+
xlab("")+
ylab("Percentage - Current Smokers") +
labs (spd=" ")+
opts(title=" ",
axis.title.y = theme_text(face = 'bold', size = 25, angle = 90),
axis.text.y=theme_text(size=25, hjust=1, face="bold"),
axis.text.x=theme_text(angle=90, hjust=1, size=25, face="bold"),
legend.text = theme_text(size= 20,hjust=1, face="bold"),
legend.title=theme_blank (),
#panel.background=theme_rect(),
plot.title = theme_text(size=24, face="bold"),
plot.title =" "
)
print (p)
ggsave(file='curr_smk_spd.png', width=11, height=7)
________________________________________
From:
ggp...@googlegroups.com [
ggp...@googlegroups.com] On Behalf Of sathish [
sathis...@gmail.com]
Sent: Friday, September 07, 2012 1:28 PM
To:
ggp...@googlegroups.com
Subject: alignment of error bar on bar chart
Hi there,
I am getting the error bar shifted towards the corner of the bars in bar chart, but I need error bars automagically placed at the center of each bar when the width of the bar is manually changed to different levels. When I changed the width of the error bar equal to the width of the bar, then the error bar moves to the center, otherwise it stays away from the center. The aesthetics of the bar chart would be much better if the error bar stays at the center and that error bar has width less than the width of the bar itself. I would appreciate any suggestion on this problem.
Thanks, Sathish
package ‘ggplot2’ version 0.9.1
df <- data.frame(trt = factor(c(1, 1, 2, 2)),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
se = c(0.1, 0.3, 0.3, 0.2))
ggplot(data = df,
aes(x = trt,
y = resp,
fill = group)) +
geom_bar(position = "dodge",
width = 0.5) +
geom_errorbar(aes(ymax = resp + se,
ymin = resp - se),
position = "dodge",
width = 0.25)
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
https://github.com/hadley/devtools/wiki/Reproducibility
To post: email
ggp...@googlegroups.com
To unsubscribe: email
ggplot2+u...@googlegroups.com
More options:
http://groups.google.com/group/ggplot2