Hello ! I am trying to learn spatial data viz in R and I found this tutorial (and associated book chapter) on Github: sdvwR. I am trying to follow the instructions: load an .shp file called "world" (I downloaded the zip from Github and saved on my desktop) and change the coordinate system:
wrld <- readOGR("Desktop/sdvw/data/", "world")
plot(wrld)
# '+proj=robin' refers to the Robinson projection
wrld.rob <- spTransform(wrld, CRS( " +proj=robin " ))
plot(wrld.rob)
so far so good. Then I need to transform it as to be able to be used by ggplot and then merge it with the @data part of the spatialPolygonsDataFrame. The code I found on github used fortify():
wrld.rob.f <- fortify(wrld.rob, region = "sov_a3" )
wrld.pop.f <- merge(wrld.rob.f, wrld.rob@data, by.x = "id" ,
by.y = "sov_a3" )
but I am not able to use it and to my understanding it is better to use tidy form the broom package, but I cannot make it work:
wrld.rob.f <- tidy(wrld.rob, region = "sov_a3" )
using "sov_a3" as region results in an error message, and if I do not use anything, a dataframe is created but then I am not able to merge it with the initial @data part, as there is no common column between the two data frames.
Does someone have an idea of how I can solve this issue?
Thanks
V.