【发布时间】:2021-01-15 00:12:49
【问题描述】:
我正在尝试重新创建此华夫饼条形图:https://github.com/hrbrmstr/waffle#waffle-bar-charts-with-scales
library(dplyr)
library(waffle)
storms %>%
filter(year >= 2010) %>%
count(year, status) -> storms_df
ggplot(storms_df, aes(fill = status, values = n)) +
geom_waffle(color = "white", size = .25, n_rows = 10, flip = TRUE) +
facet_wrap(~year, nrow = 1, strip.position = "bottom") +
scale_x_discrete() +
scale_y_continuous(labels = function(x) x * 10, # make this multiplyer the same as n_rows
expand = c(0,0)) +
ggthemes::scale_fill_tableau(name=NULL) +
coord_equal() +
labs(
title = "Faceted Waffle Bar Chart",
subtitle = "{dplyr} storms data",
x = "Year",
y = "Count"
) +
theme_minimal(base_family = "Roboto Condensed") +
theme(panel.grid = element_blank(), axis.ticks.y = element_line()) +
guides(fill = guide_legend(reverse = TRUE))
似乎geom_waffle 不再可用,现在是waffle,他们也更改了一些参数。
所以我创建了一个命名向量并修复了颜色参数,但它仍然无法正常工作:
storms %>%
filter(year >= 2010) %>%
count(status) -> storms_df2
vec = extract2(storms_df2, 'n') %>% set_names(storms_df2$status)
ggplot(storms_df, aes(fill = status, values = n)) +
waffle(vec,colors=c("red","green","blue"), size = .25, rows = 10, flip = TRUE) +
facet_wrap(~year, nrow = 1, strip.position = "bottom") +
scale_x_discrete() +
scale_y_continuous(labels = function(x) x * 10, # make this multiplyer the same as n_rows
expand = c(0,0)) +
ggthemes::scale_fill_tableau(name=NULL) +
coord_equal() +
labs(
title = "Faceted Waffle Bar Chart",
subtitle = "{dplyr} storms data",
x = "Year",
y = "Count"
) +
theme_minimal(base_family = "Roboto Condensed") +
theme(panel.grid = element_blank(), axis.ticks.y = element_line()) +
guides(fill = guide_legend(reverse = TRUE))
我错过了什么?它自己的华夫饼功能正在发挥作用,但我需要按年份制作的条形图:
waffle(vec, rows = 50, colors=c("red","green","blue"))
【问题讨论】:
-
你可以试试
remotes::install_github("liamgilbey/ggwaffle")那个包有一个工作geom_waffle。否则,请通过提供dput(storms)的输出来提供可重现性。 -
你使用的是哪个包
extract2? -
@IanCampbell,
storms是dplyr中的示例数据 -
谢谢@IanCampbell,由于某种原因,当我第一次安装 waffle 软件包时,它的所有功能都无法正常工作,即使它在安装过程中没有显示任何警告或错误。
标签: r ggplot2 waffle waffle-chart