[R] Using a constant scale across X-Y plots
Dieter Menne
dieter.menne at menne-biomed.de
Sun Dec 28 18:49:54 CET 2008
Lisa <lschwei <at> mac.com> writes:
>
> I am working off an example from Deepayan Sarkar's
> Lattice:Multivariate Data Visualiization with R. I am trying to create
> Figure 5.6, essentially, but I would like to be able depict different
> metro areas. These of course have different lat/longs, so I need to
> make different graphs. BUT (and this has been the tricky part), I
> would like to produce graphics for each metropolitan region using the
> same depth scale for all, so that dark gray means the same thing
> consistently.
...
> I'm assuming I don't have to include the quakes data to play around
> with.
You should. Please do not post incomplete examples again. It costs you
nothing to include the example from
http://lmdvr.r-forge.r-project.org/figures/figures.html
but everyone else has to find the right place or get the examples from the
book. Only when data can be used exactly as in a freshly started Rgui you
can omit these.
And linefeeds matter in R, so your example below needs a lot of reformatting.
> depth.col <- gray.colors(100)[cut(quakes$depth, 100, label = FALSE)]
>
> depth.ord <- rev(order(quakes$depth))
>
> depth.breaks <- do.breaks(range(quakes.ordered$depth), 50)
>
> quakes.ordered$color <- level.colors(quakes.ordered$depth, at =
> depth.breaks, col.regions = gray.colors)
>
> xyplot(lat ~ long | Magnitude, data = quakes.ordered, aspect = "iso",
> groups = color, cex = 2, col = "black", panel = function(x, y,
> groups, ..., subscripts) { fill <- groups[subscripts] panel.grid(h =
> -1, v = -1) panel.xyplot(x, y, pch = 21, fill = fill, ...) }, legend =
> list(right =
> list(fun = draw.colorkey, args = list(key = list(col = gray.colors, at
> = depth.breaks), draw = FALSE))), xlab = "Longitude", ylab = "Latitude")
This might give you a starter. I simply made east/west out of it, because
I do not know US definitions of metropolitan areas. Please, if you have
further questions, modify the example below and make it Gui-pastable
1:1 without additions.
------------------------
library(lattice)
quakes$Magnitude <- equal.count(quakes$mag, 4)
depth.ord <- rev(order(quakes$depth))
quakes$area <- as.factor(ifelse(quakes$long>175,"west","east"))
depth.col <- gray.colors(100)[cut(quakes$depth, 100, label = FALSE)]
quakes.ordered <- quakes[depth.ord, ]
depth.ord <- rev(order(quakes$depth))
depth.breaks <- do.breaks(range(quakes.ordered$depth), 50)
quakes.ordered$color <- level.colors(quakes.ordered$depth, at =
depth.breaks, col.regions = gray.colors)
xyplot(lat ~ long | Magnitude*area, data = quakes.ordered,
aspect = "iso", groups = color, cex = 2, col = "black",
panel = function(x, y,groups, ..., subscripts) {
fill <- groups[subscripts]
panel.grid(h =-1, v = -1)
panel.xyplot(x, y, pch = 21, fill = fill, ...) },
legend = list(
right = list(fun = draw.colorkey,
args = list(key = list(
col = gray.colors, at= depth.breaks),draw = FALSE))),
xlab = "Longitude",
ylab = "Latitude")
More information about the R-help
mailing list