我正在使用位于https://github.com/rudeboybert/fivethirtyeight的五十五岁bechdel数据集,我正在尝试重新创建文章https://fivethirtyeight.com/features/the-dollar-and-cents-case-against-hollywoods-exclusion-of-women/中显示的第一个图。我很难将这些年组合在一起,就像他们在文章中所做的那样。
这是我目前的代码:
ggplot(data = bechdel, aes(year)) +
geom_histogram(aes(fill = clean_test), binwidth = 5, position = "fill") +
scale_fill_manual(breaks = c("ok", "dubious", "men", "notalk", "nowomen"),
values=c("red", "salmon", "lightpink", "dodgerblue",
"blue")) +
theme_fivethirtyeight()
答案 0 :(得分:0)
我使用直方图geom看到你要去的地方,但这看起来更像是一个分类条形图。一旦你采用这种方法,就可以更容易了,在一些丑陋的代码之后获得年份列上的正确标签。
这个条形码的排列顺序错误,需要应用一些格式看起来像538图表,但我会留给你。
library(fivethirtyeight)
library(tidyverse)
library(ggthemes)
library(scales)
# Create date range column
bechdel_summary <- bechdel %>%
mutate(date.range = ((year %/% 10)* 10) + ((year %% 10) %/% 5 * 5)) %>%
mutate(date.range = paste0(date.range," - '",substr(date.range + 5,3,5)))
ggplot(data = bechdel_summary, aes(x = date.range, fill = clean_test)) +
geom_bar(position = "fill", width = 0.95) +
scale_y_continuous(labels = percent) +
theme_fivethirtyeight()