I am trying to create a global cartogram using the cartogram package in R. I am trying to use the data from wrld_simpl. What I expect is a cartogram in which the Population ("Pop2005" variable) is plotted. The code I have developed is this:
data(wrld_simpl)
world<-wrld_simpl
world_sf = st_as_sf(world)
world_sf_proj = st_transform(world_sf, crs = 3785)
world_cartogram <- cartogram_cont(world_sf_proj, "POP2005")
plot(world_cartogram)
Nonetheless, this has resulted in the following figure:

Do you know what is wrong with the code? Maybe the CRS? I have tried to use others CRS but I got the following error: "Error: Using an unprojected map. This function does not give correct centroids and distances for longitude/latitude data: Use "st_transform()" to transform coordinates to another projection."
Taken from this documentation, it is stated that
If you want to use the base R
plotfunction, then usest_geometry(your_map)to plot (the geometry) ansfobject.Another possibility (which I don't recommend) is to set plot options to 1 plot maximum (
options(sf_max.plot=1)), but this plots the first variable, and it might not be the best idea.Now,
sfis particularly well suited withggplot2and the tidyverse. In that setting, just useggplotin combination withgeom_sf.