[R-sig-Geo] spplot with legend only, and legend inside the plotting area

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Wed Mar 7 11:57:01 CET 2012

Hi Mauricio,

Maybe not the most elegant solution, but one possibility is to extract 
the colors and text of the legend from the spplot-object and plot it 
with legend():
p1 = spplot(xyz, cex=10, alpha=0.7)
# This has auto.key = "bottom" by default.
cols = p1$legend$bottom$args$key$points$col
txt = p1$legend$bottom$args$key$text[[1]]
legend(0.3,0.7, legend = txt, fill = cols, border = cols, bty = "n")

legend() has lots of parameters that can help you adjusting the plot if 
you need to modify the layout.


On 06-Mar-12 18:23, Mauricio Zambrano-Bigiarini wrote:
> Hi all,
> I need to produce two different spplot figures of spatial points, and 
> I would like to ask your help for the creation of the second one:
> 1) the first figure has to show the values but without any legend:
> library(sp)
> xyz = data.frame(expand.grid(x=1:10,y=1:10),rnorm(100))
> coordinates(xyz)=~x+y
> spplot(xyz, cex=10, alpha=0.7, auto.key=FALSE)
> (I don't have any problem with this)
> 2) The second figure has to show ONLY the legend for the values of the 
> previous figure (without plotting the points), inside the plotting area.
> I tried with:
> spplot(xyz, cex=0, alpha=0.7, auto.key=TRUE, key.space="center")
> but it doesn't work.
> I know that "center" is not a valid argument for 'key.space', but I 
> don't figure out how to produce this second figure.
> I would really appreciate any help with this.
> Thanks in advance,
> Mauricio Zambrano-Bigiarni

Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien at jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.

More information about the R-sig-Geo mailing list