Reputation: 37
I am a new R user and I need some help to setup a secondary legend for a map.
Description: I plotted a map using the image.plot function in the fields Library with x and y axes indicating the coordinates and a color scale with a legend andicating the attitude as describedd by the code line below:
image.plot(x,y,z,col=greyscale,legend.mar=8.5,xlab="",ylab="",main="Lambert2étendu")
Problem:
I added points the the map indicating the locations of two types of recievers with different color and cex for each type. and I want to add a legend under the map to describe each coloration signification
Thank you for help
Upvotes: 2
Views: 1419
Reputation: 3604
Use legend
for a secondary legend. Increase the bottom mar
gin and add legend with negative inset
, i.e. move away from plot:
library(fields)
x<- 1:10
y<- 1:15
z<- outer( x,y,"+")
# plot with extra margin at bottom (7)
par(mar=c(7,4,4,2)+0.1)
image.plot(x,y,z,col=gray.colors(10), xlab='', ylab='')
# create points
xp = sample(1:10,size=5)
yp = sample(1:10,size=5)
points(xp,yp,pch=21,bg=1:2,cex=1:2)
# add legend (might have to change inset if you resize the plot)
legend('bottom', horiz=T, legend=paste('type', 1:2), pt.cex=1:2, pch=21, pt.bg=1:2, xpd=NA, inset=c(0,-1..))
Upvotes: 2