Overlaying R county map onto a state map

2019-02-14 11:32发布

问题:

R newbie here.

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

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

回答1:

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.



标签: r maps