R ggplot2-关闭一个几何图形与另一个几何图形具有相同美学效果的图例

R ggplot2-关闭一个几何图形与另一个几何图形具有相同美学效果的图例,r,ggplot2,R,Ggplot2,我正在用两种不同的几何图形绘制一个图,都使用填充。我希望一个geom有一个传奇,但另一个没有。但是,将show.legend=F添加到所需的几何图形中不会关闭该几何图形的图例 示例: library(tidyverse) library(ggalluvial) x = tibble(qms = c("grass", "cereal", "cereal"), move1 = "Birth", move2 = c("Direct", "Market",

我正在用两种不同的几何图形绘制一个图,都使用填充。我希望一个geom有一个传奇,但另一个没有。但是,将
show.legend=F
添加到所需的几何图形中不会关闭该几何图形的图例

示例:

library(tidyverse)
library(ggalluvial)

x = tibble(qms = c("grass", "cereal", "cereal"),
           move1 = "Birth",
           move2 = c("Direct", "Market", "Slaughter"),
           move3 = c("Slaughter", "Slaughter", NA),
           freq = c(10, 5, 7))

x %>% 
  mutate(id = qms) %>% 
  to_lodes_form(axis = 2:4, id = id) %>% 
  na.omit() %>% 
  ggplot(aes(x = x, stratum = stratum, alluvium = id,
             y = freq, label = stratum)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow(aes(fill = qms)) +
  geom_stratum(aes(fill = stratum), show.legend=F) +
  geom_text(stat = "stratum", size = 3) +
  theme_void() +
  labs(fill="")
输出:

library(tidyverse)
library(ggalluvial)

x = tibble(qms = c("grass", "cereal", "cereal"),
           move1 = "Birth",
           move2 = c("Direct", "Market", "Slaughter"),
           move3 = c("Slaughter", "Slaughter", NA),
           freq = c(10, 5, 7))

x %>% 
  mutate(id = qms) %>% 
  to_lodes_form(axis = 2:4, id = id) %>% 
  na.omit() %>% 
  ggplot(aes(x = x, stratum = stratum, alluvium = id,
             y = freq, label = stratum)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow(aes(fill = qms)) +
  geom_stratum(aes(fill = stratum), show.legend=F) +
  geom_text(stat = "stratum", size = 3) +
  theme_void() +
  labs(fill="")

所需输出:

library(tidyverse)
library(ggalluvial)

x = tibble(qms = c("grass", "cereal", "cereal"),
           move1 = "Birth",
           move2 = c("Direct", "Market", "Slaughter"),
           move3 = c("Slaughter", "Slaughter", NA),
           freq = c(10, 5, 7))

x %>% 
  mutate(id = qms) %>% 
  to_lodes_form(axis = 2:4, id = id) %>% 
  na.omit() %>% 
  ggplot(aes(x = x, stratum = stratum, alluvium = id,
             y = freq, label = stratum)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow(aes(fill = qms)) +
  geom_stratum(aes(fill = stratum), show.legend=F) +
  geom_text(stat = "stratum", size = 3) +
  theme_void() +
  labs(fill="")

问题:

library(tidyverse)
library(ggalluvial)

x = tibble(qms = c("grass", "cereal", "cereal"),
           move1 = "Birth",
           move2 = c("Direct", "Market", "Slaughter"),
           move3 = c("Slaughter", "Slaughter", NA),
           freq = c(10, 5, 7))

x %>% 
  mutate(id = qms) %>% 
  to_lodes_form(axis = 2:4, id = id) %>% 
  na.omit() %>% 
  ggplot(aes(x = x, stratum = stratum, alluvium = id,
             y = freq, label = stratum)) +
  scale_x_discrete(expand = c(.1, .1)) +
  geom_flow(aes(fill = qms)) +
  geom_stratum(aes(fill = stratum), show.legend=F) +
  geom_text(stat = "stratum", size = 3) +
  theme_void() +
  labs(fill="")

如何关闭一个几何图形的填充图例,而不关闭另一个几何图形的填充图例?我可以(如果必须的话)在inkscape/gimp中执行此操作,但我更喜欢一个可以进行版本控制的解决方案。

查看最后一行代码:

scale_fill_discrete(breaks = c("grass", "cereal")) 
它定义了填充的中断,根据需要仅包括
谷物

库(tidyverse)
图书馆(GG)
x=tibble(qms=c(“草”、“谷物”、“谷物”),
move1=“出生”,
move2=c(“直接”、“市场”、“屠宰”),
move3=c(“屠宰”,“屠宰”,NA),
频率=c(10,5,7))
x%>%
变异(id=qms)%>%
到矿脉形态(轴=2:4,id=id)%>%
na.省略()%>%
ggplot(aes(x=x,地层=地层,冲积层=id,
y=频率,标签=地层)+
比例x离散(扩展=c(.1,.1))+
几何流量(aes(填充=qms))+
geom_地层(aes(填充=地层),显示图例=假)+
几何图形文字(stat=“地层”,尺寸=3)+
主题_void()+
实验室(fill=“”)+
比例-填充-离散(断裂=c(“草”、“谷物”))#相关