Skip to content
Prev 165612 / 398506 Next

Using a constant scale across X-Y plots

Lisa <lschwei <at> mac.com> writes:
...
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.
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")