Mapping mean values onto count diagram using ggplot2 in R -
i have data frame follows:
variable=c("d","d","c","c","c","a","b","b","b","b") value=c(80,100,70,68,65,45,33,31,36,32) count=as.integer(c(5,10,4,5,2,7,3,5,6,2)) mean=c(93.3,93.3,68.2,68.2,68.2,45,33.4,33.4,33.4,33.4) df=data.frame(variable=variable,value=value,count=count,mean=mean)
i can make nice plot (where size of square corresponds count of observations particular x-value , y-value), shown below:
ggplot(df, aes(variable, value)) + geom_point(aes(size = count), pch=15) + guides(fill=guide_legend(title="new")) + theme(legend.text=element_text(size=rel(2.3)), legend.title=element_text(size=rel(2.3), face="plain"), legend.position="right", axis.text = element_text(size=rel(2.3)), axis.title = element_text(size = rel(2.3))) + labs(x="topic", y = "percentage grade")
however, want superimpose horizontal bar each of 4 topics, indicating mean percentage grade. values stored in df$mean. cannot figure out how accomplish this. have tried using geom_line() function horizontal line option... seems plot vertical lines!
ggplot(df, aes(variable, value)) + geom_point(aes(size = count), pch=15) + guides(fill=guide_legend(title="new")) + theme(legend.text=element_text(size=rel(2.3)), legend.title=element_text(size=rel(2.3), face="plain"), legend.position="right", axis.text = element_text(size=rel(2.3)), axis.title = element_text(size = rel(2.3))) + labs(x="topic", y = "percentage grade") + geom_line(stat = "hline", yintercept = df$mean)
thank you...
you can geom_segment
:
ggplot(df, aes(variable, value)) + geom_point(aes(size = count), pch=15) + geom_segment(aes(x=variable, y=mean-.1, xend=variable, yend=mean+.1), color="red", size=i(40))
Comments
Post a Comment