Skip to content

Creating a Legend

3 messages · Steve Murray, John Fox, Baptiste Auguie

#
Dear all,

I'm trying to create a legend for my graph. I hope to have the title as "Land Use Type" and the two elements being "Urban" and "Rural" with a red point and green point respectively. So far I have the following command, but obviously it isn't correct:
As you can see, I'm a bit confused as to how to deal with the point colours and associated text.

Also, how would I make the associated text ("Urban" and "Rural") smaller than the title?


Many thanks for any suggestions!

Steve

_________________________________________________________________
Discover Bird's Eye View now with Multimap from Live Search
#
Dear Steve,

Try

legend("topright", title="Land Use Type", cex=0.75, pch=16, 
  col=c("red", "green"), legend=c("Urban", "Rural"), ncol=2)

I hope this helps,
 John

------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
On
"Land
and
obviously
colours
than
http://www.R-project.org/posting-guide.html
1 day later
#
Hi,

I think you want the following,

df <- data.frame(x=rnorm(100), y=rnorm(100))
plot(df)
legend("topright", title="Land Use Type", cex=0.75, pch=16,
		col=c("red", "green"),legend=c("Urban", "green"), ncol=2)


I could not find a way to have a different text size for the title,  
but it's easy to do in lattice or ggplot2.

Baptiste
On 23 Sep 2008, at 17:56, Steve Murray wrote:

            
_____________________________

Baptiste Augui?

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag