[R-sig-Geo] Variable point size with spplot

Paul Hiemstra paul.hiemstra at knmi.nl
Wed Mar 28 14:54:49 CEST 2012


On 03/26/2012 11:10 AM, piero campa wrote:
> Dear list,
> I used to plot points of variable size with "spplot" this way:
>
> library(RColorBrewer)
> data(meuse)
> coordinates(meuse) <- ~x+y
> spplot(meuse, zcol="om",
>         col.regions=colorRampPalette(brewer.pal(7, "PuBu")[-(1:1)])(20), 
>         scales=list(draw=TRUE), 
>         cex=.4*(1:5)
> )
>
> but now, after R upgrade, this is not working properly anymore.
> As you can see from the attached image, colors are not well linked to points
> size.
>
> Any hint?
>
> -Piero
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Variable-point-size-with-spplot-tp7405527p7405527.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Hi,

Not really an answer to your question directly, but I use ggplot2 to
make these kinds of plots. I find it more intuitive and flexible than
lattice, which is used by spplot. An example using the meuse dataset:

library(ggplot2)
data(meuse)
# Note: No coordinates is needed, ggplot2
# works with data.frames.

gg = ggplot(aes(x = x, y = y, size = om), data = meuse) + geom_point()

# A basic example:
print(gg)

# One that mimics the layout of spplot
theme_set(theme_bw())
print(gg + coord_equal() + scale_x_continuous("", breaks = NULL) +
                 scale_y_continuous("", breaks = NULL))

# ...and couple the color to the ffreq:
gg = ggplot(aes(x = x, y = y, size = om, color = ffreq), data = meuse) +
geom_point()
print(gg + coord_equal() + scale_x_continuous("", breaks = NULL) +
                 scale_y_continuous("", breaks = NULL))

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-sig-Geo mailing list