[R] "Groups" in XYPLOT

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Sun Mar 18 06:15:07 CET 2007


Much nicer, thanks, Thomas.  I've made a small change to make the
differences more obvious for this example.

#First dataset
N <- 25
x <- round(rnorm(N),2)
y <- round(rnorm(N),2)
df.1 <- data.frame(x = x, y = y)
#Plot it
xyplot(x~y,xlab="Test 1 Data",ylab="P(A>A*)", data=df.1)

#Second Dataset
N <- 20
x <- round(rnorm(N),2) + 10
y <- round(rnorm(N),2) 
df.2 <- data.frame(x = x, y = y)
#How to get this in the same panel as plot 1?
xyplot(x~y,xlab="Test 2 Data",ylab="P(A>A*)", data=df.2)

df <- make.groups(df.1, df.2) ## Thanks, Deepayan!

xyplot(x~y,
	groups=which,
	xlab="All Test Data",
	ylab="P(A>A*)",
	auto.key=list(space="right"), 
	data=df)

Cheers

Andrew



On Sat, Mar 17, 2007 at 11:48:05PM -0500, Thomas Colson wrote:
> Sorry 'bout that.
> 
> Here's about as simple as I can get it:
> 
> #First dataset
> N <- 25
> x <- round(rnorm(N),2)
> y <- round(rnorm(N),2)
> df <- data.frame(x = x, y = y)
> #Plot it
> xyplot(df$x~df$y,xlab="Test 1 Data",ylab="P(A>A*)")
> 
> #Second Dataset
> N <- 20
> x <- round(rnorm(N),2)
> y <- round(rnorm(N),2)
> df <- data.frame(x = x, y = y)
> #How to get this in the same panel as plot 1?
> xyplot(df$x~df$y,xlab="Test 2 Data",ylab="P(A>A*)")
> 
> 
> 
> 
> As far as combining that data into one dataset....I'm trying to plot both
> datasets into one panel to show the differences in the plots of the
> two...utilizing the coloring/symbology funtions...wouldn't combining them
> null that capability? 
> 
> Thanks for your replies!
> 
> 
> Thomas Colson, PhD
> North Carolina State University
> Department of Forestry and Environmental Resources
> (919)673-8023
> tpcolson at hotmail.com
> 
> Schedule: www4.ncsu.edu/~tpcolson   
> -----Original Message-----
> From: Andrew Robinson [mailto:A.Robinson at ms.unimelb.edu.au] 
> Sent: Saturday, March 17, 2007 10:44 PM
> To: Thomas Colson
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] "Groups" in XYPLOT
> 
> Hi again Thomas,
> 
> ah, sorry, I should be more precise.  Please construct a reproducible worked
> example that does not require us to download 7 Mb of data.  You might also
> try the suggestions that I made and let us know if they worked for you.
> 
> Cheers
> 
> Andrew
> 
> On Sat, Mar 17, 2007 at 10:37:46PM -0500, Thomas Colson wrote:
> >  Thanks for the warning:
> > Here is the link to the datasets, rather large at 2 and 5 mb. Another 
> > note is that one set has more datapoints than the other, don't know if 
> > this can be done with xyplot.
> > http://www4.ncsu.edu/~tpcolson/coastcurvfreqs.txt
> > http://www4.ncsu.edu/~tpcolson/coastslopefreqs.txt
> > 
> > Thomas Colson, PhD
> > North Carolina State University
> > Department of Forestry and Environmental Resources
> > (919)673-8023
> > tpcolson at hotmail.com
> > 
> > Schedule: www4.ncsu.edu/~tpcolson   
> > -----Original Message-----
> > From: Andrew Robinson [mailto:A.Robinson at ms.unimelb.edu.au]
> > Sent: Saturday, March 17, 2007 10:15 PM
> > To: Thomas Colson
> > Cc: r-help at stat.math.ethz.ch
> > Subject: Re: [R] "Groups" in XYPLOT
> > 
> > Hi Thomas,
> > 
> > sadly, the full code is not much help to us in the absence of the 
> > data.  Can I suggest that you construct a reproducible worked example 
> > to help explain your question?  For what it's worth I suspect that the 
> > answer is that you need to join these datasets into one and theneitehr 
> > use the groups argument, or the "+" protocol on the LHS of the plot
> formula.
> > 
> > Cheers
> > 
> > Andrew
> > 
> > On Tue, Mar 27, 2007 at 04:51:55PM -0500, Thomas Colson wrote:
> > > I'm not sure I'm barking up the right tree here, but would I need to 
> > > make use of groups to plot two separate datasets within ONE panel in 
> > > xyplot? The desired end result is a single xy plot of two separate 
> > > (but similar in values and ranges).
> > > 
> > > Full code follows, xyplot code at bottom
> > > 
> > > 
> > > 
> > > 
> > > 
> > > #########Determine Frequencies
> > > ##########coastal_slope
> > > #needs the maptools package to read ESRI grid
> > > require(maptools)
> > > #import the flow slope grid
> > > basin.map <- readAsciiGrid("C:/R_PLots/coastal_slp.asc",
> > > colname="slope") basin_slope <- (basin.map$slope) #read the slopes 
> > > into a dataframe
> > > freqs<-as.data.frame(table(basin_slope))
> > > #rank the frequencies based on each unique occerence, note, ranks 
> > > from
> > > 1 to n
> > > r<-rank(freqs$basin_slope)
> > > n<-length(r)
> > > #determing the probability, n+1 insures there is no 100%, 1- 
> > > reverses the order so #low slopes gets high probability of 
> > > exceedence z<-cbind(Rank = r, PRank = 1-(r/(n+1))) #attach the 
> > > probability to the table, result is high prob of exceed is in row 
> > > with low slope #and low probabibility is in row with high slope 
> > > freqs$rank<-z write.table(freqs, "C:/R_PLots/coastslopefreqs.txt", 
> > > sep=",", col.names=TRUE, row.names=TRUE, quote=TRUE, na="NA")
> > > 
> > > ##########coastal_curvature
> > > #needs the maptools package to read ESRI grid
> > > require(maptools)
> > > #import the curvature grid
> > > basin.map <- readAsciiGrid("C:/R_PLots/coastal_crv.asc",
> > > colname="curv") basin_curv <- (basin.map$curv) #read the curvs into 
> > > a dataframe
> > > freqs<-as.data.frame(table(basin_curv))
> > > #rank the frequencies based on each unique occerence, note, ranks 
> > > from
> > > 1 to n
> > > r<-rank(freqs$basin_curv)
> > > n<-length(r)
> > > #determing the probability, n+1 insures there is no 100%, 1- 
> > > reverses the order so #low curvature gets high probability of 
> > > exceedence z<-cbind(Rank = r, PRank = 1-(r/(n+1))) #attach the 
> > > probability to the table, result is high prob of exceed is in row 
> > > with low curv #and low probabibility is in row with high curv 
> > > freqs$rank<-z write.table(freqs, "C:/R_PLots/coastcurvfreqs.txt", 
> > > sep=",", col.names=TRUE, row.names=TRUE, quote=TRUE, na="NA")
> > > 
> > > 
> > > 
> > > 
> > > 
> > > ##############Make XYPLOT and export to ps coastcurv <- 
> > > read.table("C:/R_PLots/coastcurvfreqs.txt", header=TRUE, sep=",", 
> > > na.strings="NA", dec=".", strip.white=TRUE) 
> > > xyplot(coastcurv$rank.PRank~coastcurv$basin_curv,scales=list(y=list(
> > > lo
> > > g=TRUE
> > > ,at=c(.0001,.001,.01,.1,1)),x=list(log=TRUE,at=c(0.0001,0.001,0.01,0
> > > .1
> > > ,1,10)
> > > )),xlab="Curvature",ylab="P(C>C*)")
> > > dev.copy2eps(file="C:/R_PLots/coastcurv_cad.eps", width=8.0, 
> > > height=8.0,
> > > pointsize=10)
> > > 
> > > 
> > > ########How to get this in the first plot graphic?
> > > 
> > > coastslope <- read.table("C:/R_PLots/coastslopefreqs.txt",
> > > header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE) 
> > > xyplot(coastslope$rank.PRank~coastslope$basin_slope,scales=list(y=li
> > > st
> > > (log=T
> > > RUE,at=c(.0001,.001,.01,.1,1)),x=list(log=TRUE,at=c(0.0001,0.001,0.0
> > > 1,
> > > 0.1,1,
> > > 10))),xlab="Slope",ylab="P(S>S*)")
> > > dev.copy2eps(file="C:/R_PLots/coastslope_cad.eps", width=8.0, 
> > > height=8.0,
> > > pointsize=10)
> > > 
> > > Thomas Colson, PhD
> > > North Carolina State University
> > > Department of Forestry and Environmental Resources
> > > 
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > 
> > --
> > Andrew Robinson  
> > Department of Mathematics and Statistics            Tel: +61-3-8344-9763
> > University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
> > http://www.ms.unimelb.edu.au/~andrewpr
> > http://blogs.mbs.edu/fishing-in-the-bay/
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> 
> --
> Andrew Robinson  
> Department of Mathematics and Statistics            Tel: +61-3-8344-9763
> University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
> http://www.ms.unimelb.edu.au/~andrewpr
> http://blogs.mbs.edu/fishing-in-the-bay/
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/



More information about the R-help mailing list