R 带刻度的华夫格条形图
我正在尝试重新创建此华夫饼条形图: 似乎R 带刻度的华夫格条形图,r,ggplot2,waffle,waffle-chart,R,Ggplot2,Waffle,Waffle Chart,我正在尝试重新创建此华夫饼条形图: 似乎geom_waffle不再可用,现在是waffle,他们还更改了一些参数。 所以我创建了一个命名向量并修复了color参数,但它仍然不起作用: storms %>% filter(year >= 2010) %>% count(status) -> storms_df2 vec = extract2(storms_df2, 'n') %>% set_names(storms_df2$status) ggplot(
geom_waffle
不再可用,现在是waffle
,他们还更改了一些参数。
所以我创建了一个命名向量并修复了color参数,但它仍然不起作用:
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"))
如果从该存储库安装
waffle
,则可以创建此图表
install.packages("waffle", repos = "https://cinc.rud.is")
library(tidyverse)
library(waffle)
library(ggthemes)
storms %>%
filter(year >= 2010) %>%
count(year, status) -> storms_df
ggplot(storms_df, aes(fill = status, values = n)) +
geom_waffle(color = "white", 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 = "Created by Anil Goyal",
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))
我更改了副标题,只是为了表明它仍在工作。您可以尝试
remotes::install\u github(“liamgilbey/ggwaffle”)
该软件包有一个工作的geom\u waffle
。否则,请通过提供dput(storms)
的输出提供可复制的。您使用的extract2
?@IanCampbell,storms
是dplyr
中提供的样本数据,谢谢@IanCampbell,由于某种原因,当我第一次安装华夫格软件包时,它并没有让所有功能正常工作,即使它在安装过程中没有显示任何警告或错误。谢谢@AnilGoyal。我不得不重新安装我的华夫饼干包,现在它可以工作了。由于某种原因,当我第一次安装华夫格软件包时,它没有所有的功能工作,即使它在安装过程中没有显示任何警告或错误。看起来cran-r上有不同的版本
install.packages("waffle", repos = "https://cinc.rud.is")
library(tidyverse)
library(waffle)
library(ggthemes)
storms %>%
filter(year >= 2010) %>%
count(year, status) -> storms_df
ggplot(storms_df, aes(fill = status, values = n)) +
geom_waffle(color = "white", 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 = "Created by Anil Goyal",
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))