ComeçarComece de graça

Generating random dots with sf

Dot-density maps are created by randomly placing dots within areas where each dot is proportional to a certain number of observations. In this exercise, you'll learn how to create dots in this way with the sf package using the st_sample() function. You will generate dots that are proportional to about 100 people in the decennial Census, and then you will group the dots to speed up plotting with ggplot2.

Este exercício faz parte do curso

Analyzing US Census Data in R

Ver curso

Instruções do exercício

  • Use the st_sample() function to create dots where each dot represents approximately 100 people.
  • Use the mutate() function to generate a new group column named group.
  • Group by the new group column and summarize your data to speed up plotting.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Generate dots, create a group column, and group by group column
dc_dots <- map(c("White", "Black", "Hispanic", "Asian"), function(group) {
  dc_race %>%
    filter(variable == group) %>%
    ___(., size = .$value / 100) %>%
    st_sf() %>%
    ___(group = group) 
}) %>%
  reduce(rbind) %>%
  group_by(___) %>%
  summarize()
Editar e executar o código