Home > Mobile >  How can I make this graph?
How can I make this graph?

Time:10-08

I have this code here but need to make the graph below:

df.census <- census
marital.status <- census$marital_status
race <- census$race_general

ggplot(dat = df.census, mapping = aes(x = marital.status, y = race))  
 geom_point(size=marital.status)   geom_line()

enter image description here

CodePudding user response:

You can try this way.

census %>%
  group_by(sex, race_general, marital_status) %>%
  summarise(count = n()) %>%
  ggplot(aes(x = sex, y = race_general, color = sex, size = count))  
  geom_point()   facet_wrap(.~marital_status) 

enter image description here

CodePudding user response:

Like this?

library(tidyverse)
#install.packages("openintro")
library(openintro)
#> Loading required package: airports
#> Loading required package: cherryblossom
#> Loading required package: usdata

census %>% 
  ggplot(aes(x = sex, y = race_general, color = sex))  
  geom_count()  
  facet_wrap(~marital_status)  
  theme_linedraw(base_size = 14)  
  scale_size_area(name = "Count")  
  scale_x_discrete(name = "", breaks = NULL)

Created on 2021-10-08 by the reprex package (v2.0.1)

  •  Tags:  
  • r
  • Related