[R-sig-Geo] using alpha transparency for lines in spplot
Michael Sumner
mdsumner at utas.edu.au
Wed Mar 21 23:53:22 CET 2007
Hello, I'm having trouble with using the alpha channel for transparency
with lines with spplot and
sp.lines.
If I use transparency via the alpha argument to rgb to overplot lines on
spplot.grid the transparent colour affects all of the colours in the
plot. Example follows.
I've put the pdfs as created below here for reference:
http://staff.acecrc.org.au/~mdsumner/Rutas/misc/
BTW, I know my usage of the panel plots is not right, but I'm learning,
so any advice would be appreciated.
Cheers, Mike.
I'm using Windows XP, SP2 with
R version 2.4.1 (2006-12-18)
i386-pc-mingw32
locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252
attached base packages:
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
[7] "base"
other attached packages:
sp
"0.9-9"
Example:
library(sp)
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
## create some lines
bb <- bbox(meuse.grid)
xy <- cbind(runif(10, bb[1,1], bb[1,2]), runif(10, bb[2,1], bb[2,2]))
ll <- SpatialLines(list(Lines(list(Line(xy)), "1")))
## this is fine, colour grid with black lines
pdf("test.pdf", version = "1.4")
pg <- function(...) {
panel.gridplot(...)
sp.lines(ll)
}
spplot(meuse.grid[1], panel = pg)
dev.off()
## in this the colour grid is "greyed" like the lines
pdf("testAlpha.pdf", version = "1.4")
pg <- function(...) {
panel.gridplot(...)
sp.lines(ll , col = rgb(190, 190, 190, 100, max = 255))
}
spplot(meuse.grid[1], panel = pg)
dev.off()
## try with blue lines - colour grid is "blued" . . .
pdf("testBlueAlpha.pdf", version = "1.4")
pg <- function(...) {
panel.gridplot(...)
sp.lines(ll , col = rgb(0, 0, 190, 100, max = 255))
}
spplot(meuse.grid[1], panel = pg)
dev.off()
More information about the R-sig-Geo
mailing list