[R] legend position

David Carlson dcarlson at tamu.edu
Mon Dec 2 21:29:06 CET 2013


It is not straightforward unless you want the legend in the
right or the bottom margins. To put the legend inside the plot
region it is simplest to use image() to plot the raster file and
then image.plot(legend.only=TRUE) to add the legend. In addition
to reading the help page for plot{raster}, you also need the
pages for image{raster} and image.plot{fields}. Here are two
simple examples.

image(r,  col=rev(terrain.colors(255)))
plot(r, horizontal=TRUE, smallplot=c(.15, .5, .84, .86),
legend.only=TRUE)

image(r,  col=rev(terrain.colors(255)))
plot(r, smallplot=c(.15, .17, .5, .85), legend.only=TRUE)

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of philippe
massicotte
Sent: Monday, December 2, 2013 1:22 PM
To: r-help at r-project.org
Subject: [R] legend position

Hi all. 
I'm ploting a raster and I can't find the proper way to move the
legend. For example,
r = raster(system.file("external/test.grd",
package="raster"))plot(r)
How can I put the legend at the desired position?
Thank in advance,Phil 		 	   		  
	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible
code.



More information about the R-help mailing list