Home > OS >  Editing a tmap data file in R
Editing a tmap data file in R

Time:10-15

I'm new to using tmap. I'm using the default "World" map and I'm able to create a world map and color all the countries according to life expectancy simply using:

library(tmap)
library(sf)
tm_shape(World)  
  tm_polygons("life_exp") 

But now, I've created my own dataframe to merge with the World dataframe.

World2 <- merge(World, df, by="iso_a3")

This works and I now have a nice merged dataframe that includes my variables. But when I got to run it, I get this:

Error: Object World2 is neither from class sf, stars, Spatial, Raster, nor SpatRaster.

Is there something special I need to do to the merged dataframe to make it work here?

CodePudding user response:

You need to convert your dataframe into a sf type object. I guess the following line should solve your problem :

World2 <- st_sf(World2)

  • Related