[R] lattice: double y - problem changing axis color after doubleYScale
Duncan Mackay
dulcalma at bigpond.com
Sun Sep 22 05:00:16 CEST 2013
Hi Anna
I am not sure what you want but the following should get you part of the way
I prefer to keep all my parameters within the function rather than use
themes.
useOuterStrips(strip = strip.custom(#factor.levels = ,
par.strip.text =
list(fontfamily="serif" )),
strip.left = strip.custom(#factor.levels = ,
par.strip.text =
list(fontfamily="serif" )),
xyplot(mean ~ Week | Station*fyear, data= SummPdata,
col="black",
pch=2,
cex=1.1,
lty=2,
par.settings = list(strip.background = list(col =
"transparent"),
add.text = list(fontfamily = "serif"
)),
#strip = strip.custom(#factor.levels = ,
# par.strip.text =
list(fontfamily="serif" )),
scales = list(alternating = c(3,3),
fontfamily = "serif"),
ylab = list(text = "Pc", fontfamily = "serif"),
xlab=list(text = "Week", fontfamily = "serif"),
key = list(text = list(labels = c("P","N")),
points = list(pch = c(2,20)),
lines = list(lty = c(1,2))),
type = "o",
ylim = c(0,70),
subscripts = TRUE,
panel = function(x,y, subscripts, ...){
panel.xyplot(x,y, ...)
# sd
# upper
panel.arrows(x0 = x, x1 = x,
y0 = y, y1 = y+ SummPdata[subscripts,
"sd"]/2, angle = 90, length = 0.04)
# lower
panel.arrows(x0 = x, x1 = x,
y0 = y, y1 = y- SummPdata[subscripts,
"sd"]/2, angle = 90, length = 0.04)
panel.xyplot(x+0.1, SummNdata[subscripts,"mean"],
type ="o",pch = 20, lty =1, col = "black")
# sd
# upper
panel.arrows(x0 = x+0.1, x1 = x+0.1,
y0 = SummNdata[subscripts,"mean"], y1
= SummNdata[subscripts,"mean"] + SummNdata[subscripts, "sd"]/2, angle = 90,
length = 0.04)
# lower
panel.arrows(x0 = x+0.1, x1 = x+0.1,
y0 = SummNdata[subscripts,"mean"], y1
= SummNdata[subscripts,"mean"]- SummNdata[subscripts, "sd"]/2, angle = 90,
length = 0.04)
}# panel
)#
) ## useOuterStrips
Note that I offset the N data so that the error bars are more legible
For sd I just divided them by 2 so you will have to work out what you
require
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Anna Zakrisson Braeunlich
Sent: Thursday, 19 September 2013 20:21
To: r-help at r-project.org
Subject: [R] lattice: double y - problem changing axis color after
doubleYScale
Hi,
I have had some troubles using doubleYScale. No matter what I try, I cant
manage to change the color of the y-axis in the end. I have to produce a
black and white plot. There is also something I do not understand regarding
fontfamilyj="serif" when using it in:
strip=strip.custom()
Maybe someone has a better idea for defining which line and dots belong to
which y-axis when not using a colorcode than the one I had.
I have annotated my questions in the code below.
Thank you for your time!
Here is some dummy data:
Ndata <- data.frame(
Ncellpercent = rnorm(400, mean = rep(c(14, 18, 65), each = 40),
sd = rep(c(1, 3, 6), each = 40)),
fyear = rep(c('2007', '2008'), each = 100*2),
Station = sample(c('B1', 'H2', 'H3', 'H4'), 400, replace = TRUE),
Week = sample(c('19', '21', '23', '25'), 400, replace = TRUE))
Pdata <- data.frame(
Ppercentcell = rnorm(400, mean = rep(c(4, 17, 22), each = 40),
sd = rep(c(0.1, 0.2, 0.4), each = 40)),
fyear = rep(c('2007', '2008'), each = 100*2),
Station = sample(c('B1', 'H2', 'H3', 'H4'), 400, replace = TRUE),
Week = sample(c('19', '21', '23', '25'), 400, replace = TRUE))
SummNdata <- ddply(Ndata, .(Week, fyear, Station), summarise,
mean = mean(Ncellpercent),
sd = sd(Ncellpercent))
names(Pdata)
SummPdata <- ddply(Pdata, .(Week, fyear, Station), summarise,
mean = mean(Ppercentcell),
sd = sd(Ppercentcell))
library(lattice)
library(latticeExtra)
library(HH)
font.settings <- list( font = 1, cex = 1.2, fontfamily = "serif")
my.theme <- list(
par.xlab.text = font.settings,
par.ylab.text = font.settings,
axis.text = font.settings,
par.sub=font.settings)
plotN <- xyplot(mean ~ Week | Station*fyear,
col="black",
pch=1,
cex=1.1,
lty=1,
strip = strip.custom(bg = 'white', style=1), # why can I not
use fontfamily="serif" here ???
key=list(text=list(c(""),
col=c("black")),
points=list(pch=1, lty=1, cex=1.5,
col=c("black")),
columns=1, border=F,
x = 0.02, y = 0.55, corner = c(2, 2),
title="", cex.title=1.3),
ylab = ("Nc"),
xlab="Week",
data= SummNdata,type="o",
par.settings = my.theme) plotN # I would like to add the
standard deviations (sd) to the plot. I have tried some stuff, # but for
some reason, it does not seem to work. How would I go about this?
plotP <- xyplot(mean ~ Week | Station*fyear,
col="black",
pch=2,
cex=1.1,
lty=2,
strip = strip.custom(bg = 'white', style=1), # why can I not
use fontfamily="serif" here ???
key=list(text=list(c(""),
col=c("black")),
points=list(pch=1, lty=1, cex=1.5,
col=c("black")),
columns=1, border=F,
x = 0.2, y = 0.2, corner = c(2, 2),
title="", cex.title=1.3),
ylab = ("Pc"),
xlab="Week",
data= SummPdata,type="o",
par.settings = my.theme) plotP
doubleYScale(plotN, plotP, add.ylab2 = TRUE) #Why can I not change the axis
color by adding to this argument?
# I want the y1 and y2 axes to be defined not by color, but by shape and
linetype.
# I have managed to draw the shapes (defined by Nc and Pc) by the y1 and y2
axes, but I do not manage to get the lines # though the shape - ideas?
# Alternative ways that are not based on color (I have to do this black and
white).
# Is there possible to add shapes to the axis text? such as:
# --O-- Nc on the left y-axis (but with lty=1: I could not do a non-dotted
line on the keybord).
with kind regards
Anna Zakrisson Braeunlich
PhD student
Department of Ecology, Environment and Plant Sciences Stockholm University
Svante Arrheniusv. 21A
SE-106 91 Stockholm
Sweden/Sverige
Lives in Berlin.
For paper mail:
Katzbachstr. 21
D-10965, Berlin - Kreuzberg
Germany/Deutschland
E-mail: anna.zakrisson at su.se
Tel work: +49-(0)3091541281
Mobile: +49-(0)15777374888
LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b
><((((:>`. . `. . `. . ><((((:>`. . `. . `. .><((((:>`. .
>`. . `. .><((((:>
[[alternative HTML version deleted]]
More information about the R-help
mailing list