[R] qplot/ggplot2 Questions
David Winsemius
dwinsemius at comcast.net
Tue Jun 21 20:09:01 CEST 2011
On Jun 21, 2011, at 1:03 PM, wwreith wrote:
> 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"
var <- factor(var) will by default give a factor variable which most
plotting functions will display in alpha order.
>
>
> 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?
>
?hist # see the 'freq' argument
or
require(lattice)
?histogram # use ... , type="percent")
--
david
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list