Choroplethmapbox & 2 custom Geojsons - US works but Ireland does not. Why?

Have fixed/worked around this. Looks like I should have RTFM’ed more closely. Para 4.2.1 of https://plotly-r.com/maps.html#maps-custom says *

“By simply providing a z attribute, plotly_geo() objects will try to create a choropleth, but you’ll also need to provide locations and a locationmode. It’s worth noting that the locationmode is currently limited to countries and US states, so if you need to a different geo-unit (e.g., counties, municipalities, etc), you should use the choroplethmapbox trace type and/or use a “custom” mapping approach as discussed in Section 4.2.”*

This explains why the US map works but the Ireland one does not. In the end, I found it easier & more effective to use the sf simple feature package & mapview as below:

schools_grp <- schools %>%
select(County, M_13_14, F_13_14, T_13_14) %>% group_by(County) %>%
summarize(nrows = n(),
total_male = sum(M_13_14),
mean_male = mean(M_13_14, na.rm = TRUE),
total_female = sum(F_13_14),
mean_female = mean(F_13_14, na.rm = TRUE),
total_both = sum(T_13_14),
mean_both = mean(T_13_14, na.rm = TRUE)) %>%
mutate(char_county = as.character(County)) %>%
select(-County)

url_gj <- paste(c(
https://gist.githubusercontent.com/pnewall/”,
“9a122c05ba2865c3a58f15008548fbbd/raw/”,
“572888440cec7059e2fd55802756e59aca83f51e/”,
“ireland-counties.geojson”),
collapse = “”)

Make the geojson simple feature from the file at the url above
then merge with the schools data on the county name

sf <- geojson_sf(url_gj)
schools_grp_sf <- merge(sf, schools_grp, by.x = “name”, by.y = “char_county”)

Set the column names so the chart output looks better

colnames(schools_grp_sf) <- c(“County”, “Nr of Schools”, “Total Male Pupils”, “Mean Nr of Males per School”, “Total Female Pupils”, “Mean Nr Females per School”, “Total Pupils”, “Mean Nr of Pupils per School”, “Geometry”)

st_geometry(schools_grp_sf) <- “Geometry”

p3 <- mapview(schools_grp_sf,
zcol = c(“Nr of Schools”, “Total Pupils”, “Mean Nr of Pupils per School”),
col.regions = sf.colors(5), lwd = 1,
popup = popupTable(schools_grp_sf, row.numbers = FALSE, feature.id = FALSE))

1 Like