Also, it is possible to change "ylim" also? 2012/7/1 li li <hannah.hlx@gmail.com>> Dear all, > I have a few questions regarding the boxplot output from the > "geom_boxplot" function. > Attached is the output I get. Below are my questions: > > 1. How can I define the xlab and ylab myself? > Also I would like to remove "factor(variable)" > line on the right side. > > 2. How can I define the colors of the boxplots myself. > For example, I want to use blue for > "LR", green for "pair" and purple for "BR1". > Thanks so much! > Hannah >[[alternative HTML version deleted]]
Dear all, I have a few questions regarding the boxplot output from the "geom_boxplot" function. Take as an example the output of the below: library(ggplot2) p <- ggplot(mtcars, aes(factor(cyl), mpg)) p + geom_boxplot(aes(fill = factor(am))) Here are my questions: 1. How can I define the xlab and ylab myself? Also I would like to remove "factor(am)" line on the right side. 2. How can I define the colors of the boxplots myself. 3. Is it possible to change ylim also? I looked at the R help document and did not see how to do these. Thanks so much! Hannah [[alternative HTML version deleted]]
Yes you can do all of the things you want. Below is a start, to give you an idea of how to approach some of it. ===================================================library(ggplot2) p <- ggplot(mtcars, aes(factor(cyl), mpg)) p <- p + geom_boxplot(aes(fill = factor(cyl))) + labs(fill = "Cylinders") + scale_y_continuous("Miles per Gallon") + scale_x_discrete("Number of Cylinders") p ===========================================================Have a look at ackoverflow.com/questions/3606697/how-to-set-x-axis-limits-in-ggplot2-r-plots for x and y axes limits. It took me a while to realise it but, generally, I find that it is not too hard to find examples of what you need by just googling something like :ggplot2 set x and y limits or ggplot2 geom_bar colour and so on. The ggplot2 and geom_XXX are pretty unique on the internet and search results usually are not too bad. You may also want to subcribe to the ggplot2 group on google groups. Best wishes John Kane Kingston ON Canada> -----Original Message----- > From: hannah.hlx at gmail.com > Sent: Sun, 1 Jul 2012 08:39:20 -0400 > To: r-help at r-project.org > Subject: Re: [R] geom_boxplot > > Also, it is possible to change "ylim" also? > > 2012/7/1 li li <hannah.hlx at gmail.com> > >> Dear all, >> I have a few questions regarding the boxplot output from the >> "geom_boxplot" function. >> Attached is the output I get. Below are my questions: >> >> 1. How can I define the xlab and ylab myself? >> Also I would like to remove "factor(variable)" >> line on the right side. >> >> 2. How can I define the colors of the boxplots myself. >> For example, I want to use blue for >> "LR", green for "pair" and purple for "BR1". >> Thanks so much! >> Hannah >> > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!
Hi In new ggplot2 version following works too p + geom_boxplot(aes(fill = factor(cyl))) + labs(fill = "Cylinders") + ylab("Miles per Gallon")+xlab("Number of Cylinders") Regards Petr> > Yes you can do all of the things you want. > > Below is a start, to give you an idea of how to approach some of it. > ===================================================> library(ggplot2) > p <- ggplot(mtcars, aes(factor(cyl), mpg)) > p <- p + geom_boxplot(aes(fill = factor(cyl))) + > labs(fill = "Cylinders") + > scale_y_continuous("Miles per Gallon") + > scale_x_discrete("Number of Cylinders") > p > > ===========================================================> Have a look atackoverflow.com/questions/3606697/how-to-set-x-axis-limits-> in-ggplot2-r-plots for x and y axes limits. > > It took me a while to realise it but, generally, I find that it is nottoo> hard to find examples of what you need by just googling something like > :ggplot2 set x and y limits or ggplot2 geom_bar colour and so on. > > The ggplot2 and geom_XXX are pretty unique on the internet and search > results usually are not too bad. > > You may also want to subcribe to the ggplot2 group on google groups. > > Best wishes > > > John Kane > Kingston ON Canada > > > > -----Original Message----- > > From: hannah.hlx at gmail.com > > Sent: Sun, 1 Jul 2012 08:39:20 -0400 > > To: r-help at r-project.org > > Subject: Re: [R] geom_boxplot > > > > Also, it is possible to change "ylim" also? > > > > 2012/7/1 li li <hannah.hlx at gmail.com> > > > >> Dear all, > >> I have a few questions regarding the boxplot output from the > >> "geom_boxplot" function. > >> Attached is the output I get. Below are my questions: > >> > >> 1. How can I define the xlab and ylab myself? > >> Also I would like to remove "factor(variable)" > >> line on the right side. > >> > >> 2. How can I define the colors of the boxplots myself. > >> For example, I want to use blue for > >> "LR", green for "pair" and purple for "BR1". > >> Thanks so much! > >> Hannah > >> > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > ____________________________________________________________ > FREE ONLINE PHOTOSHARING - Share your photos online with your friendsand family!> Visit http://www.inbox.com/photosharing to find out more! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Thanks Petr, I suppose this means I have to reread that set of changes again. I think I noticed it and promptly forgot it. John Kane Kingston ON Canada> -----Original Message----- > From: petr.pikal at precheza.cz > Sent: Mon, 2 Jul 2012 10:41:20 +0200 > To: jrkrideau at inbox.com > Subject: Re: [R] geom_boxplot > > Hi > > In new ggplot2 version following works too > > p + geom_boxplot(aes(fill = factor(cyl))) + > labs(fill = "Cylinders") + ylab("Miles per Gallon")+xlab("Number > of > Cylinders") > > Regards > Petr > >> >> Yes you can do all of the things you want. >> >> Below is a start, to give you an idea of how to approach some of it. >> ===================================================>> library(ggplot2) >> p <- ggplot(mtcars, aes(factor(cyl), mpg)) >> p <- p + geom_boxplot(aes(fill = factor(cyl))) + >> labs(fill = "Cylinders") + >> scale_y_continuous("Miles per Gallon") + >> scale_x_discrete("Number of Cylinders") >> p >> >> ===========================================================>> Have a look at > ackoverflow.com/questions/3606697/how-to-set-x-axis-limits- >> in-ggplot2-r-plots for x and y axes limits. >> >> It took me a while to realise it but, generally, I find that it is not > too >> hard to find examples of what you need by just googling something like >> :ggplot2 set x and y limits or ggplot2 geom_bar colour and so on. >> >> The ggplot2 and geom_XXX are pretty unique on the internet and search >> results usually are not too bad. >> >> You may also want to subcribe to the ggplot2 group on google groups. >> >> Best wishes >> >> >> John Kane >> Kingston ON Canada >> >> >>> -----Original Message----- >>> From: hannah.hlx at gmail.com >>> Sent: Sun, 1 Jul 2012 08:39:20 -0400 >>> To: r-help at r-project.org >>> Subject: Re: [R] geom_boxplot >>> >>> Also, it is possible to change "ylim" also? >>> >>> 2012/7/1 li li <hannah.hlx at gmail.com> >>> >>>> Dear all, >>>> I have a few questions regarding the boxplot output from the >>>> "geom_boxplot" function. >>>> Attached is the output I get. Below are my questions: >>>> >>>> 1. How can I define the xlab and ylab myself? >>>> Also I would like to remove "factor(variable)" >>>> line on the right side. >>>> >>>> 2. How can I define the colors of the boxplots myself. >>>> For example, I want to use blue for >>>> "LR", green for "pair" and purple for "BR1". >>>> Thanks so much! >>>> Hannah >>>> >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> 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. >> >> ____________________________________________________________ >> FREE ONLINE PHOTOSHARING - Share your photos online with your friends > and family! >> Visit http://www.inbox.com/photosharing to find out more! >> >> ______________________________________________ >> 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!