I have a data frame as 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 a nice plot (where the size of the square corresponds to the count of observations with that particular x-value and y-value), as 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, I now want to superimpose a horizontal bar to each of the four topics, indicating the mean percentage grade. Those values are stored in df$mean. I cannot figure out how to accomplish this. I have tried using the geom_line() function with the horizontal line option... but this seems to 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...