Rich Shepard
2011-Aug-31 20:50 UTC
[R] Scatter Plot Command Syntax Using Data.Frame Source
I've tried various commands. ?plot, Teetor's book, "R Cookbook", and Mittal's book, "R Graphs Cookbook" without seeing how to write the command to create scatterplots from my data.frame. The structure is:> str(chemdata)'data.frame': 14886 obs. of 4 variables: $ site : Factor w/ 148 levels "BC-0.5","BC-1",..: 104 145 126 115 114 128 124 2 3 3 ... $ sampdate: Date, format: "1996-12-27" "1996-08-22" ... $ param : Factor w/ 8 levels "As","Ca","Cl",..: 1 1 1 1 1 1 1 1 1 1 ... $ quant : num 0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 ... and what I'd like to do is create scatter plots of quant (y-axis) against the factor site (x-axis) for specified param factors. Teetor has an example for a data set with two numeric variables and a single factor. I have a single numeric veriable, two factors, and a date. I'll also want to create time series line plots of values as a function of date for specified params. If the data.frame had only two columns all the examples work. But, using two columns (the number per site factor for only a specified param factor) is not covered in what I've read so far. Other graphing resources about which I should know? Rich
baptiste auguie
2011-Aug-31 21:10 UTC
[R] Scatter Plot Command Syntax Using Data.Frame Source
Hi, Below are a couple of options using a standard dataset, str(iris) ## using base graphics d <- split(iris, iris$Species) str(d) # list of 3 data.frames par(mfrow=n2mfrow(length(d))) # split the device in 3 plotting regions b.quiet <- lapply(names(d), function(x) { # loop over the list names with(d[[x]], plot(Sepal.Length, Petal.Length)) title(x) }) library(ggplot2) # using facetting ggplot(iris) + facet_wrap(~Species) + geom_point(aes(Sepal.Length, Petal.Length)) library(lattice) # using facetting xyplot(Petal.Length ~ Sepal.Length | Species, data=iris ) HTH, baptiste On 1 September 2011 08:50, Rich Shepard <rshepard at appl-ecosys.com> wrote:> ?I've tried various commands. ?plot, Teetor's book, "R Cookbook", and > Mittal's book, "R Graphs Cookbook" without seeing how to write the command > to create scatterplots from my data.frame. The structure is: > >> str(chemdata) > > 'data.frame': ? 14886 obs. of ?4 variables: > ?$ site ? ?: Factor w/ 148 levels "BC-0.5","BC-1",..: 104 145 126 115 114 > 128 124 2 3 3 ... > ?$ sampdate: Date, format: "1996-12-27" "1996-08-22" ... > ?$ param ? : Factor w/ 8 levels "As","Ca","Cl",..: 1 1 1 1 1 1 1 1 1 1 ... > ?$ quant ? : num ?0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 ... > > ?and what I'd like to do is create scatter plots of quant (y-axis) against > the factor site (x-axis) for specified param factors. Teetor has an example > for a data set with two numeric variables and a single factor. I have a > single numeric veriable, two factors, and a date. > > ?I'll also want to create time series line plots of values as a function of > date for specified params. > > ?If the data.frame had only two columns all the examples work. But, using > two columns (the number per site factor for only a specified param factor) > is not covered in what I've read so far. > > ?Other graphing resources about which I should know? > > Rich > > ______________________________________________ > 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. >
Rich Shepard
2011-Aug-31 21:14 UTC
[R] Scatter Plot Command Syntax Using Data.Frame Source
On Thu, 1 Sep 2011, baptiste auguie wrote:> Below are a couple of options using a standard dataset,Thanks, Baptiste. These point me in the right direction. Rich
Jorge I Velez
2011-Aug-31 21:17 UTC
[R] Scatter Plot Command Syntax Using Data.Frame Source
Hi Rich, Using the data set "iris" as an example, you might also try require(car) scatterplot(Petal.Length ~ Sepal.Length | Species, data = iris) HTH, Jorge On Wed, Aug 31, 2011 at 4:50 PM, Rich Shepard <> wrote:> I've tried various commands. ?plot, Teetor's book, "R Cookbook", and > Mittal's book, "R Graphs Cookbook" without seeing how to write the command > to create scatterplots from my data.frame. The structure is: > > str(chemdata) >> > 'data.frame': 14886 obs. of 4 variables: > $ site : Factor w/ 148 levels "BC-0.5","BC-1",..: 104 145 126 115 114 > 128 124 2 3 3 ... > $ sampdate: Date, format: "1996-12-27" "1996-08-22" ... > $ param : Factor w/ 8 levels "As","Ca","Cl",..: 1 1 1 1 1 1 1 1 1 1 ... > $ quant : num 0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 ... > > and what I'd like to do is create scatter plots of quant (y-axis) against > the factor site (x-axis) for specified param factors. Teetor has an example > for a data set with two numeric variables and a single factor. I have a > single numeric veriable, two factors, and a date. > > I'll also want to create time series line plots of values as a function of > date for specified params. > > If the data.frame had only two columns all the examples work. But, using > two columns (the number per site factor for only a specified param factor) > is not covered in what I've read so far. > > Other graphing resources about which I should know? > > Rich > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]