Tile grid map for Canada provinces & territories

using this as R code:
install.packages(c("tilemaps", "sf"))
library(tilemaps)
library(sf)
library(dplyr)
library(ggplot2)
governors <- governors %>%
mutate(tile_map = generate_map(geometry, square = FALSE, flat_topped = TRUE))
head(governors)

ggplot(governors) +
geom_sf(aes(geometry = tile_map)) +
geom_sf_text(aes(geometry = tile_map, label = abbreviation),
fun.geometry = function(x) st_centroid(x)) +
theme_void()

I am trying to build a Canadian Tile map. I got the geometry (lpr_000b16a_e.shp found https://open.canada.ca/data/en/dataset/47bd4f2e-1c77-49f8-8406-dc4dca64ee6b) from statistics Canada.

when I am using the R code above, I am getting this error:
Error: Problem with mutate() input tile_map.
x regions are not contiguous i Input tile_map is `generate_map(geometry, square = FALSE, flat_topped = TRUE)

How can I create a tile map of the Canada provinces?

Hi @silpai, and welcome!
How are you reading in the shapefile and converting it to a simple features object? The following works for me:

library(tilemaps)
library(sf)
library(dplyr)
library(ggplot2)

canada_sf <- read_sf("~/Downloads/lpr_000a16a_e/lpr_000a16a_e.shp") %>%
  mutate(tile_map = generate_map(geometry, square = FALSE, flat_topped = TRUE))

ggplot(canada_sf) +
geom_sf(aes(geometry = tile_map)) +
geom_sf_text(aes(geometry = tile_map, label = PREABBR),
fun.geometry = function(x) st_centroid(x)) +
theme_void() 

Thank you very much for the code, I guess it was how I was reading the shp

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.