Tmap Error - replacement has [x] lines, data has [y]

Short version: when you run the following command, the qtm(countries, "freq")following error message appears:

The error is in $<-.data.frame( *tmp*, "SHAPE_AREAS", value = c (652270.070308042 ,: replacement has 177 rows, data has 210

Disclaimer: I have already checked other answers, such as this or this and also this explanation , which says that usually this error comes from spelling objects, but cannot find the answer to my problem.

Playable Code:

library(rgdal)
library(dplyr)
library(tmap)

# Load JSON file with countries.
countries = readOGR(dsn = "https://gist.githubusercontent.com/ccamara/fc26d8bb7e777488b446fbaad1e6ea63/raw/a6f69b6c3b4a75b02858e966b9d36c85982cbd32/countries.geojson")

# Load dataframe.
df = read.csv("https://gist.githubusercontent.com/ccamara/fc26d8bb7e777488b446fbaad1e6ea63/raw/754ea37e4aba1b7ed88eaebd2c75fd4afcc54c51/sample-dataframe.csv")


countries@data = left_join(countries@data, df, by = c("iso_a2" = "country_code"))

qtm(countries, "freq")
0
source share
1 answer

- .

:

1) 1:1

2) , .csv ,

3)

, , :

library(dplyr)

df_unique = df %>%
    group_by(country_code, country_name) %>%
    summarize(total = sum(total), freq = sum(freq))


#after that you should be fine - as long as just adding up the data is okay.
countries@data = left_join(countries@data, df, by = c("iso_a2" = 
"country_code"))

qtm(countries, "freq")
+1

All Articles