jftuga
jftuga

Reputation: 1963

Overlaying R county map onto a state map

R newbie here.

If I first use map('state'), how can I then use map('county', ylim=..., xlim=...) but offset it like this:

overlay

Right now, I am using imagemagick's composite -gravity southwest ... to combine 2 PNG files, but this seems less than ideal.

Upvotes: 4

Views: 1749

Answers (1)

thelatemail
thelatemail

Reputation: 93803

You can use the fig option in a graphics parameter call to set the region where a figure will be plotted.

map("state")
par(fig=c(0.1,0.9,0,0.6), new=TRUE, xpd=NA)
map("county",regions="california",add=TRUE)

In regards to the other code, xpd=NA lets you plot in the margins of a plot while new=TRUE makes sure you don't scrap the existing plot when starting a new plot. Adding add=TRUE to the end of the plot for the county acts similarly to the new=TRUE call.

enter image description here

Upvotes: 6

Related Questions