Friday, April 5, 2013

RG#7: bar chart with error bar


# data
  cmon<- c(600,250,150,135,350, 124)
cities <- c("A","B","C","D","E", "F")

error <- c(50, 33, 20, 15, 18, 12)
#plot
#using lattice plot package (often comes with base installation)
# using col pallette heat.colors so that we have different color for different bars

 require(lattice)
barchart (cmon~ cities, col= heat.colors(5), ylab = "CM level (ppm)", xlab = " cities ")


 
#using ggplot2
 require(ggplot2)
 plt <- qplot(cities, cmon, geom="bar", fill = cities, ylab = " carbon mono oxide level(ppm) ", xlab = " cities ") + theme_bw( )


# adding error bars
plt +  geom_errorbar(aes(ymin=cmon-error, ymax=cmon+error), width=.1, position=position_dodge(.1))

 
 
 
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.