[R] "Groups" in XYPLOT

Thomas Colson tpcolson at ncsu.edu
Tue Mar 27 23:51:55 CEST 2007


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(log=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=list(log=T
RUE,at=c(.0001,.001,.01,.1,1)),x=list(log=TRUE,at=c(0.0001,0.001,0.01,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



More information about the R-help mailing list