Just a quick tip to add the number of observation of each bar of a barplot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# Data name= c("DD","with himself","with DC","with Silur" ,"DC","with himself","with DD","with Silur" ,"Silur","with himself","with DD","with DC" ) average= sample(seq(1,10) , 12 , replace=T) number= sample(seq(4,39) , 12 , replace=T) data=data.frame(name,average,number) # Basic Barplot my_bar=barplot(data$average , border=F , names.arg=data$name , las=2 , col=c(rgb(0.3,0.1,0.4,0.6) , rgb(0.3,0.5,0.4,0.6) , rgb(0.3,0.9,0.4,0.6) , rgb(0.3,0.9,0.4,0.6)) , ylim=c(0,11) , main="" ) abline(v=c(4.9 , 9.7) , col="grey") # Add the text text(my_bar, data$average+0.4 , paste("n = ",data$number,sep="") ,cex=1) #Legende legend("topleft", legend = c("Alone","with Himself","With other genotype" ) , col = c(rgb(0.3,0.1,0.4,0.6) , rgb(0.3,0.5,0.4,0.6) , rgb(0.3,0.9,0.4,0.6) , rgb(0.3,0.9,0.4,0.6)) , bty = "n", pch=20 , pt.cex = 2, cex = 0.8, horiz = FALSE, inset = c(0.05, 0.05)) |
Not what you are looking for ? Make a new search !
[mediatagger]
Leave a Reply
1 Comment on "#37 Barplot with number of observation"
How to add error bars based on this plot?