Ryan Flaherty
2013-Feb-04 19:37 UTC
[R] is it possible to create a trellis object with multiple colorkeys/z-scale axis?
Dear R users-
Do the lattice/latticeExtra packages support multiple tileplots with unique
colorkeys? I am trying to create a visualization of the encounter rate of
certain stocks of salmon across two years. The issue I am having is that
some stocks are encountered at much higher rates than others.the high
encounter rate for one stock washes out the patterns I'm hoping to visualize
across the other, less common, stocks. In the example below, the high
encounter rate of Central Valley Fall (CVF) in San Francisco (SF) during
June of 2011 makes it impossible to identify differences in encounter rate
of the other stocks. Is there a way to create the same plot but with a
unique colorkey for each panel?
#Please first load packages RCurl and latticeExtra
#Import data
getdata<-getURL("https://docs.google.com/spreadsheet/pub?hl=en&hl=en&key=0Aj
zYZNH9Dw9qdENjREl2ZkVlcFA4MDN2S1h6Vi03ZUE&single=true&gid=0&output=csv",ssl.
verifypeer=FALSE)
test<-read.csv(textConnection(getdata),header=T)
test$year<-as.factor(test$year)
head(test)
##Custom color ramp
jet.colors <-
colorRampPalette(c("#00007F", "blue", "#007FFF",
"cyan",
"#7FFF7F", "yellow",
"#FF7F00", "red", "#7F0000"))
##create trellis of tileplots
betweenyear<-tileplot(index~month*-area|stock+year,test,col.regions=jet.colo
rs(256),
scales=list(x=list(at=5:9, labels=c('May'
,'Jun','Jul','Aug','Sep'),cex=0.6),
y=list(at=(-1):-8,labels=c('T','N','C','B','KC','FB','SF','MO'))),
main = list(label="Stock specific encounter rate by WCGSI: 2010
versus 2011",cex=0.75) ,
xlab= "Month",
ylab= "Management Area",
border = "black",
panel = function(...){
panel.fill("black")
panel.voronoi(...)
})
##plot object
plot(betweenyear)
Thank you for your time and consideration.
Regards,
Ryan
Ryan Flaherty
Oregon State University
College of Oceanic and Atmospheric Science
Marine Resource Management
541-513-0293
rflaherty at coas.oregonstate.edu
Richard M. Heiberger
2013-Feb-04 20:06 UTC
[R] is it possible to create a trellis object with multiple colorkeys/z-scale axis?
This will get you started
library(lattice)
library(latticeExtra)
D1 <- data.frame(y=1:3, x=4:6)
D2 <- data.frame(y=7:10, x=11:14)
T1 <- xyplot(y ~ x, data=D1,
key=list(space="right", text=list(LETTERS[1:3],
col=c("red","green","blue"))))
T2 <- xyplot(y ~ x, data=D2,
key=list(space="right", text=list(LETTERS[4:7],
col=c("orange","purple","brown","pink"))))
c(T1, T2, layout=c(1,2), merge.legends=TRUE)
Rich
On Mon, Feb 4, 2013 at 2:37 PM, Ryan Flaherty
<ryan1.flaherty@gmail.com>wrote:
> Dear R users-
>
> Do the lattice/latticeExtra packages support multiple tileplots with unique
> colorkeys? I am trying to create a visualization of the encounter rate of
> certain stocks of salmon across two years. The issue I am having is that
> some stocks are encountered at much higher rates than others.the high
> encounter rate for one stock washes out the patterns I'm hoping to
> visualize
> across the other, less common, stocks. In the example below, the high
> encounter rate of Central Valley Fall (CVF) in San Francisco (SF) during
> June of 2011 makes it impossible to identify differences in encounter rate
> of the other stocks. Is there a way to create the same plot but with a
> unique colorkey for each panel?
>
> #Please first load packages RCurl and latticeExtra
>
> #Import data
> getdata<-getURL("
> https://docs.google.com/spreadsheet/pub?hl=en&hl=en&key=0Aj
>
zYZNH9Dw9qdENjREl2ZkVlcFA4MDN2S1h6Vi03ZUE&single=true&gid=0&output=csv
> ",ssl.
> verifypeer=FALSE)
> test<-read.csv(textConnection(getdata),header=T)
> test$year<-as.factor(test$year)
> head(test)
>
> ##Custom color ramp
> jet.colors <-
> colorRampPalette(c("#00007F", "blue",
"#007FFF", "cyan",
> "#7FFF7F", "yellow",
"#FF7F00", "red", "#7F0000"))
>
> ##create trellis of tileplots
>
>
betweenyear<-tileplot(index~month*-area|stock+year,test,col.regions=jet.colo
> rs(256),
> scales=list(x=list(at=5:9, labels=c('May'
> ,'Jun','Jul','Aug','Sep'),cex=0.6),
>
y=list(at=(-1):-8,labels=c('T','N','C','B','KC','FB','SF','MO'))),
> main = list(label="Stock specific encounter rate by WCGSI:
2010
> versus 2011",cex=0.75) ,
> xlab= "Month",
> ylab= "Management Area",
> border = "black",
> panel = function(...){
> panel.fill("black")
> panel.voronoi(...)
> })
>
> ##plot object
> plot(betweenyear)
>
> Thank you for your time and consideration.
>
> Regards,
>
> Ryan
>
> Ryan Flaherty
> Oregon State University
> College of Oceanic and Atmospheric Science
> Marine Resource Management
> 541-513-0293
> rflaherty@coas.oregonstate.edu
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
Possibly Parallel Threads
- latticeExtra tileplot question - tiles are not all the same size, need help.
- adding tick labels to tileplot()
- read.csv fails to read a CSV file from google docs
- Can levelplot colorkeys display a logarithmic scale evenly?
- Convert tileplot's trellis to shapefile/ Add values to voronoi polygon