[R] qplot/ggplot2 Questions

wwreith reith_william at bah.com
Tue Jun 21 19:03:43 CEST 2011


I took some data from an online poll about which R GUI people used most and I
am messing around with it to learn how to use qplot. Specifically I am
making a horizontal bar graph and I have two questions.


1. The categories are ordered in rather strange way at least to me. It is
not alphabetical or ascending/descending order of votes cast so i had to
manually state the order I wanted which is fine, but is there an easy way
put the cateogies in alphabetical order or in my case descending order?
Maybe something like: order="alphabetical" 


2. Is there an easy way to take a bar graph of count data and turn it into a
bar graph of percentages. I know I can count how many items are in each
category then divide by the total and then graph that, but is there
something quick like geom="percent" or something that would do it
automatically?  


Code:


library(ggplot2)
x<-R.GUI.Poll$Poll
q<-qplot(x, main="Most Popular R-GUIs", ylab="Votes Received", xlab="R GUI",
fill=I("blue"), colour=I("black"))+coord_flip()+scale_x_discrete(
limits=c("R via a data mining tool plugin","Rexcel","JGR (Java Gui for
R)","RKWard","Revolution Analytics","R Commander","Rattle GUI","ESS (Emacs
Speaks Statistics)","Tinn-R","RapidMiner R extension","Eclipse with
StatET","Rstudio","Built-in R console"))
q<-q+opts(axis.text.x = theme_text(colour = "black", size = 12))
q<-q+opts(plot.title = theme_text(colour = "black", face="bold", size = 16,
vjust=2))
q<-q+opts(axis.text.y = theme_text(colour = "black", hjust=1))
q<-q+opts(axis.title.y = theme_text(face= "bold", size= 12, angle=90))
q<-q+opts(axis.title.x = theme_text(face= "bold", size= 12, vjust=-.5))
q

--
View this message in context: http://r.789695.n4.nabble.com/qplot-ggplot2-Questions-tp3614722p3614722.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list