您的代码中有一个打字错误-您在facet_wrap()
之后遗漏了+
.如果您更正此错误,您可以根据需要调整标签,例如
library(tidyverse)
df <- read_csv("https://data.cityofnewyork.us/api/views/833y-fsy8/rows.csv?accessType=DOWNLOAD")
#> Rows: 27312 Columns: 21
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (12): OCCUR_DATE, BORO, LOC_OF_OCCUR_DESC, LOC_CLASSFCTN_DESC, LOCATION...
#> dbl (7): INCIDENT_KEY, PRECINCT, JURISDICTION_CODE, X_COORD_CD, Y_COORD_CD...
#> lgl (1): STATISTICAL_MURDER_FLAG
#> time (1): OCCUR_TIME
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df %>%
drop_na(VIC_SEX) %>%
ggplot(aes(x = BORO))+
geom_bar(aes(fill = BORO), show.legend = FALSE)+
facet_wrap(~ VIC_RACE) +
theme_bw()+
theme(axis.text.x = element_text(angle = 45))+
labs(title = "Dangerous Boroughs based on Race",
x = "Borough",
y = "Number of Shootings")
# adjust label placement
df %>%
drop_na(VIC_SEX) %>%
ggplot(aes(x = BORO))+
geom_bar(aes(fill = BORO), show.legend = FALSE)+
facet_wrap(~ VIC_RACE) +
theme_bw()+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
labs(title = "Dangerous Boroughs based on Race",
x = "Borough",
y = "Number of Shootings")
创建于2023-09-15年第reprex v2.0.2页