Does something like the code below give you want you want?

It requires the ggplot2 package so you will likely have to install it.

John Kane
Kingston ON Canada

====================================================


# sample data converted using dput
xx <- structure(list(X = c("Exp1", "Exp1", "Exp1", "Exp1", "Exp1", 
"Exp1", "Exp2", "Exp2", "Exp2", "Exp2"), M = c(-90.0273224, -73.33333333, 
-98.24561404, -65.2173913, -98.7654321, -96.42857143, -84.61538462, 
-43.63636364, -47.5, -55.49450549), F = c(-77.66531714, -96.36363636, 
-91.57848325, -59.18367347, -92.42424242, -89.25925926, -47.36842105, 
-22.37762238, -33.33333333, -66.66666667)), .Names = c("X", "M", 
"F"), class = "data.frame", row.names = c(NA, -10L))

# melt data using reshape --automatically loads with ggplot2
library(ggplot2)
mm <- melt(xx, id="X")

ggplot(mm, aes(variable, value, fill=variable)) + geom_boxplot() + 
         opts(legend.position="none")  + facet_grid(. ~ X) 
         

====================================================

> -----Original Message-----
> From: ap...@neuro.mpg.de
> Sent: Mon, 20 Feb 2012 18:59:49 +0000
> To: jrkrid...@inbox.com, r-help@r-project.org
> Subject: RE: [R] overlay of two sets of boxplots
> 
> 
> Hello John,
> Thanks for your fast answer. I will try to be clearer and more detailed
> this time. At the moment I am importing a dataframe like below as a '.csv
> file'. I want to generate a boxplot for M and F values grouped by X
> whereby boxplots for M and F should be above or very close to each other.
> Please see attachment for example figure. Till now I have tried a code
> that looks like the one below the frame (I found it in the graph help of
> R for boxes close to each other):
> 
> X     M                        F
> Exp1  -90.0273224     -77.66531714
> Exp1  -73.33333333    -96.36363636
> Exp1  -98.24561404    -91.57848325
> Exp1  -65.2173913     -59.18367347
> Exp1  -98.7654321     -92.42424242
> Exp1  -96.42857143    -89.25925926
> Exp2  -84.61538462     -47.36842105
> Exp2  -43.63636364     -22.37762238
> Exp2  -47.5                  -33.33333333
> Exp2  -55.49450549    -66.66666667
> 
> >boxplot(
>     formula = F~Strain,
>     data    = pain,
>     boxwex  = 0.25,
>     at      = 1:38 - 0.1,
>     subset  =supp== "F",
>     col     = "red",
>     xlab    = "Strain",
>     ylab    = " F"
>                        )
> boxplot(
>     formula = M~Strain,
>     data    = pain,
>     boxwex  = 0.25,
>     at      = 1:38 + 0.1,
>     subset  =supp== "M",
>     col     = "orange",
>     add     = TRUE )
> 
> ...but I did cannot find anywhere what supp means and R cannot read it.
> I hope this is explained ok. Any kind of answer would help!
> Best
> Mirjam
> 
> -----Original Message-----
> From: John Kane [mailto:jrkrid...@inbox.com]
> Sent: Monday, February 20, 2012 6:00 PM
> To: Mirjam Appel; r-help@r-project.org
> Subject: RE: [R] overlay of two sets of boxplots
> 
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> At a rough guess you may want to have a look at the mfrow in ?par  but
> without some sample data and a bit more information about what you need
> it is difficult to suggest more.
> 
> By the way dput (see ?dput) is a handy way to supply a sample data set
> here.
> 
> John Kane
> Kingston ON Canada
> 
> 
>> -----Original Message-----
>> From: ap...@neuro.mpg.de
>> Sent: Mon, 20 Feb 2012 10:27:11 +0000
>> To: r-help@r-project.org
>> Subject: [R] overlay of two sets of boxplots
>> 
>> Hello,
>> I am new to R and currently have the following problem:
>> I have successfully loaded my data in R which consists of two numeric
>> columns (LI_F and female) and one character column (Strain). So far I
>> can plot two different set of boxplots for each of the numeric columns
>> plotted by the groups of the character column and the commands look
>> like
>> that:
>> 
>> boxplot(LI_F~Strain, ylab="LI_F", xlab="Strain", data=pain)
>> boxplot(female~Strain, ylab="female", xlab="Strain", data=pain)
>> 
>> How can I overlay the two set of boxplots (preferably in different
>> colors), so that I can compare them one by one, meaning two boxplots
>> corresponding to the same character in "Strain" are directly above
>> each other?
>> I have tried a lot of things and would greatly appreciate your help.
>> 
>> Best,
>> Mirjam
>> 
>>      [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help@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.
> 
> ____________________________________________________________
> Receive Notifications of Incoming Messages Easily monitor multiple email
> accounts & access them with a click.
> Visit http://www.inbox.com/notifier and check it out!

____________________________________________________________
Share photos & screenshots in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1
Works in all emails, instant messengers, blogs, forums and social networks.

______________________________________________
R-help@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.

Reply via email to