[R] Lattice legend
Seth W Bigelow
sbigelow at fs.fed.us
Wed Jun 23 02:05:09 CEST 2010
Here is the code for my recent query:
The first part just sets up the data. It's the last part
titled "individual depth graph" where the actual graphics code comes in
Thx
--Seth
library(lattice)
setwd("c:/sethdocs/3 Light and PLAS txs/8 Figures/Fg 6 Soil wetness")
d <- read.table("2007 data.txt", header=TRUE, sep = ",")
str(d)
CC <- rep(6:96,3)
depth <- rep(1:3, each=91)
g <- data.frame(depth, CC)
### 0 - 15 PRE parms ####
model <- function(a, b, f, CC){
t <- a + exp(f-(b*CC))
return(t)
}
a = 0.08
b = 0.275
f = -1.18
g$t <- ifelse(g$depth==1,round(model(a, b, f, g$CC),3),g$t==NA)
# g$depth = rep("0-15",nrow(g))
### 15 - 40 PRE parms ######
a <- 0.14
b <- 0.0683
f <- -1.9
g$t <- ifelse(g$depth==2, round(model(a, b, f, g$CC),3),g$t)
####### 40 - 70 PRE parms, graphs ##############
a <- 0.291
b <- -0.00094
}
a <- 0.25
g$t <- ifelse(g$depth==3, a, g$t)
s <- split(g, depth)
######## Individual depth graph ###############################
sup.sym <- Rows(trellis.par.get("superpose.symbol"),1:4)
sup.sym
sup.sym$pch[1:4] <- c(6,2,0,1)
# show.settings()
mypanel <- function(..., alt.data){
panel.xyplot(...)
with(alt.data[[which.packet()[1]]], # 'with' evaluates
statement and includes with version of dataset in local workspace
panel.xyplot(x = CC, y = t, type="l", col="black"))
}
graf <- xyplot(t~CC|dep,d, groups=tx, alt.data=s,
pch = sup.sym$pch,
cex=1.5, # symbol
size
layout = c(3,1),
xlab = list("Canopy cover (%)", cex=1.7),
ylab = list(expression(paste("soil moisture
(m"^{"3"},"/m"^{"3"},")")),
cex=1.2),
scales=list(x = list(cex=1.3), y = list(cex=1.3)),
strip = strip.custom(bg="transparent"),
panel = mypanel,
key = list(
text = c("heavy thin","light thin", "control"," group"),
columns=2,
points=list(pch=sup.sym)
),
aspect="xy")
graf
Dr. Seth W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
Felix Andrews <felix at nfrac.org>
Sent by: foolish.android at gmail.com
06/22/2010 04:29 PM
To
Seth W Bigelow <sbigelow at fs.fed.us>
cc
Subject
Re: [R] Lattice legend
Plase post your code (to the list). We can't help if we don't know
what you are doing.
Cheers
-Felix
On 23 June 2010 08:54, Seth W Bigelow <sbigelow at fs.fed.us> wrote:
> I have a moderately complex graph with three panels. There are data
points
> plotted, and fitted lines are added using a panel function, which
includes
>
> "with(alt.data[[which.packet()[1]]]" statements. It all graphs out
> beautifully, but none of the usual tricks to get the proper legend to
plot
> are working, i.e., using auto.key, key, etc.
> One message I keep getting is
>
> Error in key[[i]][[1]] <- NULL : more elements supplied than there are
to
> replace
>
>
>
> Any suggestions will be appreciated
>
> --Seth
>
>
> Dr. Seth W. Bigelow
> Biologist, USDA-FS Pacific Southwest Research Station
> 1731 Research Park Drive, Davis California
> ______________________________________________
> 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.
>
>
--
Felix Andrews / 安福立
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
--
http://www.neurofractal.org/felix/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 2007 data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100622/0b31e240/attachment.txt>
More information about the R-help
mailing list