Dear R users, I have a matrix "final" which looks like this: final oSO4 oNO3 mSO4 mNO3 [1,] 3.3728 0.2110 1.9517421 1.01883602 [2,] 0.8249 0.0697 1.5970292 0.11368781 [3,] 0.2636 0.1004 0.6012445 0.24356332 [4,] 8.0072 0.3443 6.1016998 3.63207149 [5,] 13.5079 0.6593 12.4011068 1.55323386 [6,] 6.1293 0.1989 5.7620926 0.12884845 [7,] 0.6004 0.0661 0.7375408 0.17218600 [8,] 0.6912 0.1672 1.1563314 0.13469750 [9,] 1.0478 0.1504 1.5637809 0.99000758 [10,] 0.4825 0.1160 0.2297545 0.08121805 I would like to create boxplots for this matrix with data binned by oNO3, oSO4, mNO3 and mSO4, all in the same plot. I tried boxplot(final), boxplot(final[,1]) etc. But all those commands create individual plots and not what I am trying to achieve. I was wondering if there is an R equivalent of the matlab command "hold on" or if there is a simpler way around this. [[alternative HTML version deleted]]
Check out ggplot2: http://had.co.nz/ggplot2 Particularly: http://had.co.nz/ggplot2/geom_boxplot.html Looks like you'll have to melt your data to long format first though, here's a tutorial: http://www.statmethods.net/management/reshape.html On Mon, Feb 2, 2009 at 8:19 PM, Vemuri, Aparna <avemuri at epri.com> wrote:> Dear R users, > > I have a matrix "final" which looks like this: > > final > oSO4 oNO3 mSO4 mNO3 > [1,] 3.3728 0.2110 1.9517421 1.01883602 > [2,] 0.8249 0.0697 1.5970292 0.11368781 > [3,] 0.2636 0.1004 0.6012445 0.24356332 > [4,] 8.0072 0.3443 6.1016998 3.63207149 > [5,] 13.5079 0.6593 12.4011068 1.55323386 > [6,] 6.1293 0.1989 5.7620926 0.12884845 > [7,] 0.6004 0.0661 0.7375408 0.17218600 > [8,] 0.6912 0.1672 1.1563314 0.13469750 > [9,] 1.0478 0.1504 1.5637809 0.99000758 > [10,] 0.4825 0.1160 0.2297545 0.08121805 > > I would like to create boxplots for this matrix with data binned by > oNO3, oSO4, mNO3 and mSO4, all in the same plot. > > I tried > boxplot(final), boxplot(final[,1]) etc. But all those commands create > individual plots and not what I am trying to achieve. I was wondering if > there is an R equivalent of the matlab command "hold on" or if there is > a simpler way around this. > > > > [[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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University www.thatmike.com Looking to arrange a meeting? Check my public calendar: http://www.thatmike.com/mikes-public-calendar ~ Certainty is folly... I think. ~
Hi Vemuri: is this what you want? x <- "oSO4 oNO3 mSO4 mNO3 3.3728 0.2110 1.9517421 1.01883602 0.8249 0.0697 1.5970292 0.11368781 0.2636 0.1004 0.6012445 0.24356332 8.0072 0.3443 6.1016998 3.63207149 13.5079 0.6593 12.4011068 1.55323386 6.1293 0.1989 5.7620926 0.12884845 0.6004 0.0661 0.7375408 0.17218600 0.6912 0.1672 1.1563314 0.13469750 1.0478 0.1504 1.5637809 0.99000758 0.4825 0.1160 0.2297545 0.08121805" df <- read.table(textConnection(x),header=T) attach(df) df <- data.frame(oSO4,oNO3,mSO4,mNO3) df boxplot(df,col="limegreen") # Or with ggplot2 library(ggplot2) x <- melt(df) x boxPlots <- qplot(factor(variable),value,data=x,geom="boxplot",colour=I("magenta"),fill=I("lightgoldenrod")) boxPlots Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA --- On Mon, 2/2/09, Vemuri, Aparna <avemuri at epri.com> wrote:> From: Vemuri, Aparna <avemuri at epri.com> > Subject: [R] Boxplots by variable > To: r-help at r-project.org > Date: Monday, February 2, 2009, 4:19 PM > Dear R users, > > I have a matrix "final" which looks like this: > > final > oSO4 oNO3 mSO4 mNO3 > [1,] 3.3728 0.2110 1.9517421 1.01883602 > [2,] 0.8249 0.0697 1.5970292 0.11368781 > [3,] 0.2636 0.1004 0.6012445 0.24356332 > [4,] 8.0072 0.3443 6.1016998 3.63207149 > [5,] 13.5079 0.6593 12.4011068 1.55323386 > [6,] 6.1293 0.1989 5.7620926 0.12884845 > [7,] 0.6004 0.0661 0.7375408 0.17218600 > [8,] 0.6912 0.1672 1.1563314 0.13469750 > [9,] 1.0478 0.1504 1.5637809 0.99000758 > [10,] 0.4825 0.1160 0.2297545 0.08121805 > > I would like to create boxplots for this matrix with data > binned by > oNO3, oSO4, mNO3 and mSO4, all in the same plot. > > I tried > boxplot(final), boxplot(final[,1]) etc. But all those > commands create > individual plots and not what I am trying to achieve. I was > wondering if > there is an R equivalent of the matlab command "hold > on" or if there is > a simpler way around this. > > > > [[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.
Does boxplot(as.data.frame(final)) do what you want? --Adam On Mon, 2 Feb 2009, Vemuri, Aparna wrote:> Dear R users, > > I have a matrix "final" which looks like this: > > final > oSO4 oNO3 mSO4 mNO3 > [1,] 3.3728 0.2110 1.9517421 1.01883602 > [2,] 0.8249 0.0697 1.5970292 0.11368781 > [3,] 0.2636 0.1004 0.6012445 0.24356332 > [4,] 8.0072 0.3443 6.1016998 3.63207149 > [5,] 13.5079 0.6593 12.4011068 1.55323386 > [6,] 6.1293 0.1989 5.7620926 0.12884845 > [7,] 0.6004 0.0661 0.7375408 0.17218600 > [8,] 0.6912 0.1672 1.1563314 0.13469750 > [9,] 1.0478 0.1504 1.5637809 0.99000758 > [10,] 0.4825 0.1160 0.2297545 0.08121805 > > I would like to create boxplots for this matrix with data binned by > oNO3, oSO4, mNO3 and mSO4, all in the same plot. > > I tried > boxplot(final), boxplot(final[,1]) etc. But all those commands create > individual plots and not what I am trying to achieve. I was wondering if > there is an R equivalent of the matlab command "hold on" or if there is > a simpler way around this. > > > > [[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. >