【发布时间】:2021-02-26 10:29:42
【问题描述】:
我试图更改我的图例和在其中一个区域图中多次出现的国家/地区的名称。
我。如您所见,图例出现了好几次。我希望这个传说出现在最后一张照片中。对于两者:症状和合并症:
- 如果这可以在整个图上方显示为:症状:胸痛、发冷等和合并症:哮喘、1 型糖尿病等。
二。每个区域地块的大小不同
- 它们的大小应该相同。
三。还有国家标签。很好,这些只出现过一次。希望它们看起来像最后一张图片:
A - 印度, B - 巴基斯坦, C - 英国,位于每组面积图上方的左侧。
这是代码和假数据集:
sympt_count_plot <- ggplot2::ggplot(count_symptoms, ggplot2::aes(x = age_band, y = Count, group = symptoms, fill = symptoms)) +
ggplot2::geom_area( color = "white") +
ggplot2::scale_x_discrete(limits = c( "0-19" ,"20-39", "40-59","60+"), expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
viridis::scale_fill_viridis(discrete = TRUE) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
ggplot2::facet_grid(Country ~.)
sympt_count_plot
sympt_percent_plot <- ggplot2::ggplot(count_symptoms, ggplot2::aes(x = age_band, y = Percent, group = symptoms, fill = symptoms)) +
ggplot2::geom_area( color = "white") +
ggplot2::scale_x_discrete(limits = c( "0-19" ,"20-39", "40-59","60+"), expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
viridis::scale_fill_viridis(discrete = TRUE) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
ggplot2::facet_grid(Country ~.)
sympt_percent_plot
library(patchwork)
plot_sympt <- sympt_count_plot + sympt_percent_plot
plot_sympt
comorb_count_plot <- ggplot2::ggplot(count_comorbidities, ggplot2::aes(x = age_band, y = Count, group = comorbidities, fill = comorbidities)) +
ggplot2::geom_area( color = "white") +
ggplot2::scale_x_discrete(limits = c( "0-19" ,"20-39", "40-59","60+"), expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
#viridis::scale_fill_viridis(discrete = TRUE) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
ggplot2::facet_grid(Country ~.)
comorb_count_plot
comorb_percent_plot <- ggplot2::ggplot(count_comorbidities, ggplot2::aes(x = age_band, y = Percent, group = comorbidities, fill = comorbidities)) +
ggplot2::geom_area( color = "white") +
ggplot2::scale_x_discrete(limits = c( "0-19" ,"20-39", "40-59","60+"), expand = c(0, 0)) +
ggplot2::scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
#viridis::scale_fill_viridis(discrete = TRUE) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
ggplot2::facet_grid(Country ~.)
comorb_percent_plot
plot_comorb <- comorb_count_plot + comorb_percent_plot
plot_comorb
plot_sympt + plot_comorb
有没有办法让我按照我想要的方式获得它们。非常感谢您的帮助。
【问题讨论】:
标签: r ggplot2 size legend patchwork