Reputation: 2876
Could someone please point me to the current recommended solution for plotting world maps? (I have been using rworldmap
(obsoletes via maptools
, rgdal
, and rgeos
) and made some progress on raster
(suggests terra
), but both are telling me that they are themselves or that they rely on legacy packages, and will go away soon. Most solutions on stackoverflow are therefore going out of date.)
Simple starter needs. (Think world temperatures and temperature anomaly.)
Plot a worldmap with continents or countries, and then plot data values over them. I sometimes have data values by (countries,value), I sometimes have data values as (lat,lon,value) grid points (which would be nice to be smoothed, too). Color scheme red to green or red to blue. Ideally, also a choice of map projection and option for latitude/longitude lines. That's it.
I need something like a vignette or starter examples. Pointers would be greatly appreciated.
Upvotes: 0
Views: 263
Reputation: 47686
You are asking many questions in one, but here is how you can get country boundaries using terra/geodata
library(geodata)
w <- world(path=".")
plot(w)
points(cbind(c(0, 10), c(0, 10)), col="red", cex=2, pch=20)
w
is a SpatVector, as defined in the "terra" package.
Here are two approaches to making more fancy maps (with base plot and ggplot). And here is a short tutorial.
You can also use the "sf" package. If you were using w
you would first need to do
library(sf)
wsf <- st_as_sf(w)
Upvotes: 2