gpt4 book ai didi

r - ggpattern - 指定变量值的模式

转载 作者:行者123 更新时间:2023-12-05 05:32:21 26 4
gpt4 key购买 nike

我试图将物种存在表现在容器繁殖地中。我使用条形图和颜色代码来代表我的不同物种。我首先尝试为我的 sp 变量的每个值指定一种颜色,但它看起来颜色太多,因为我在繁殖地点有多个物种的组合。为了简化情节的视觉效果,我试图通过在另一个物种的颜色之上添加一个物种的彩色图案来表示同一容器中存在两个物种,但没有成功。

下面是我使用的代码。我试过但不明白scale_pattern_manual的使用

有什么建议吗?

x11(); ggppt<-Tabagg %>%
filter(!(type_gîtes %in% "na")) %>%
filter(pres_larve %in% "Oui") %>%
filter(!(sp %in% "na")) %>%
ggplot() +
aes(x = type_gîtes, fill = sp) +
geom_bar() +
labs(x = "Type gîte",
y = "N", fill = "Espèces") +
coord_flip() +
theme_minimal() +
theme(legend.text.align = 0,
legend.position = "bottom")+
scale_fill_manual(name = "Espèces" ,
values = c("Ae. aegypti" = "#DA4943",
"Ae. aegypti + Ae. polynesiensis" = "#D058EC",
"Ae. aegypti + Ae. polynesiensis + Cx. spp." = "#FF27D5",
"Ae. aegypti + Cx. spp." = "#EC8158",
"Ae. aegypti + Toxo. amboinensis" = "#CC804D",
"Ae. polynesiensis" = "#5284D9",
"Ae. polynesiensis + W. mitchellii" = "#CB447C",
"Cx. spp." = "#E5AD3F",
"Toxo. amboinensis" = "#67E5C8",
"W. mitchellii" = "#A259DB",
"na" = "#757575"
),
labels = c(expression(italic("Ae. aegypti"),
italic("Ae. aegypti + Ae. polynesiensis"),
italic("Ae. aegypti + Ae. polynesiensis + Cx. spp."),
italic("Ae. aegypti + Cx. spp."),
italic("Ae. aegypti + Toxo. amboinensis"),
italic("Ae. polynesiensis"),
italic("Ae. polynesiensis + W. mitchellii"),
italic("Cx. spp."),
italic("Toxo. amboinensis"),
italic("W. mitchellii"),
"na"))) +
geom_bar_pattern()+
scale_pattern_manual(values=c("Ae. aegypti + Ae. polynesiensis" ="Stripe")); ggppt

这是生成的图

enter image description here

最佳答案

你可能想尝试这样的事情:

数据

library(tidyverse)
library(ggpattern)

dat <- data.frame(drv = c("4", "4", "4", "4", "4", "f", "f", "f", "f", "r", "r", "r"),
class = c("compact", "midsize", "pickup", "subcompact", "suv",
"compact", "midsize", "minivan", "subcompact",
"2seater", "subcompact", "suv"),
y = c(12L, 3L, 33L, 4L, 51L, 35L, 38L, 11L, 22L, 5L, 9L, 11L))

dat

scale_fill_manual()scale_pattern_manual() 命名。此外,指定您想要显示模式的组(或组)。

dat %>% ggplot(aes(x = class, y = y, fill = drv, pattern = drv)) +
# geom_col()+ # not necessary
geom_col_pattern() +
coord_flip() +
theme_minimal() +
scale_fill_manual(
name = "Drive",
values = c(
"4" = "#DA4943",
"f" = "#D058EC",
"r" = "#FF27D5"
)
) +
scale_pattern_manual(
name = "Drive",
values = c(
"4" = "none",
"f" = "stripe",
"r" = "none"
)
)

enter image description here

关于r - ggpattern - 指定变量值的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74159276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com