Hello , please I am trying to remove NA from my ggplot, so that I have three plots instead of four. Also is there a way to remove Unknown from gender, so that my fill=gender will take only Male and Female? Thanks in anticipation
#install packages
pacman:: p_load(rio,janitor, here, tidyverse, datapasta, reprex)
# load data ---------------------------------------------------------------
line_clean<-data.frame(
stringsAsFactors = FALSE,
report_date = c("2020-09-17","2021-05-18",
"2021-01-06","2021-05-30","2020-04-08","2021-03-26",
"2021-03-22","2020-12-07","2020-05-22","2020-06-17",
"2021-01-22","2020-10-12","2020-11-08","2021-01-26",
"2020-08-18","2020-08-01","2021-01-07","2021-02-08",
"2020-06-10","2020-12-06","2021-03-27","2020-12-24",
"2021-05-06","2021-03-17","2021-02-07","2021-04-01",
"2021-01-05","2020-07-18","2020-06-20","2020-04-02",
"2020-08-03","2021-01-31","2020-08-16","2020-08-10",
"2020-12-04","2020-08-09","2020-12-18","2020-04-29","2020-11-11",
"2020-08-21"),
gender = c("Male","Female","Female",
"Male","Male","Female","Female","Female","Female",
"Male","Female","Female","Female","Male","Male","Male",
"Female","Female","Female","Male","Female","Female",
"Unknown","Male","Male","Male","Female","Female",
"Male","Female","Female","Male","Female","Male",
"Female","Male","Male","Female","Male","Male"),
case_race = c("BLACK","OTHER","BLACK",
"BLACK","WHITE","WHITE","BLACK","WHITE",NA,NA,"WHITE",
"WHITE","BLACK","WHITE","OTHER","BLACK","WHITE",
"BLACK","BLACK","WHITE","BLACK","WHITE","OTHER",
"WHITE","WHITE","BLACK",NA,"BLACK","WHITE","BLACK",
"WHITE","WHITE","WHITE","WHITE",NA,"WHITE","WHITE",
"BLACK","BLACK","BLACK")
)
clean<-line_clean %>%
clean_names() %>%
mutate(report_date=ymd(report_date))
clean %>%
ggplot(mapping= aes(x=report_date, fill=gender) )+
geom_histogram()+
scale_x_date(date_breaks = "3 months", labels = scales::label_date_short())+
facet_wrap(~case_race)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
[image]
Created on 2024-03-07 with reprex v2.0.2
Session info