I'm trying to map the census data and plotting different ethnic groups:
I'm partially following this tutorial (GitHub - RobWHickman/sf.dotdensity: Simple Dot Chloropleth Maps using sf)
but when I'm trying to calculate the dot positions for each column I get this error:
Error in calc_dots(df = bndukshp.df.proj.data.2017, col_names = allgroups, :
could not find function "calc_dots"
Thank you @FJCC but now I've got this error: Error in UseMethod("st_geometry") :
no applicable method for 'st_geometry' applied to an object of class "data.frame"
I am shooting in the dark here having never used this package or sf. I notice that the last step on Robert Hickman's blog before running calc-dots is to use st_as_sf()
language_data %<>%
#convert number of speakers to numeric
mutate(primary_speakers = as.numeric(as.character(primary_speakers))) %>%
#matching of area names with South African shapefile
mutate(region = gsub(" NU", "", region)) %>%
mutate(region = gsub("Tshwane", "City of Tshwane", region)) %>%
#filter only the data we want to merge
filter(region %in% south_africa$region) %>%
filter(!is.na(language)) %>%
filter(language != "Not applicable") %>%
#spread the data
dcast(., region ~ language, value.var = "primary_speakers", fun.aggregate = sum) %>%
#join in the spatial geometry
left_join(., south_africa) %>%
#convert to sf
st_as_sf()
If that does not fix your problem, please try to post a reproducible example. There are several posts and tutorials about how to do that. Here is one: FAQ: Reprex, How To