R 尝试将颜色更改为灰度ggplot2时,图例消失
我本想把它做成这样黑白的,但是线条是一样的,不再有传说了。我做错了什么R 尝试将颜色更改为灰度ggplot2时,图例消失,r,ggplot2,R,Ggplot2,我本想把它做成这样黑白的,但是线条是一样的,不再有传说了。我做错了什么 graph %>% mutate(Obstacle = fct_relevel(Obstacle, "No Obstacle", "Minor Obstacle", "Moderate Obstacle", "Major Obstacle")) %>% ggplot(aes(x = Obstacle, y=value, co
graph %>%
mutate(Obstacle = fct_relevel(Obstacle, "No Obstacle", "Minor Obstacle", "Moderate Obstacle", "Major Obstacle")) %>%
ggplot(aes(x = Obstacle, y=value, colour=variable, group = variable)) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) +
geom_line()
试试这个:
库(dplyr)
图书馆(GG2)
图书馆(供猫用)
图表%>%
#重塑2::熔化(图形,id=“障碍”)%>%
变异(障碍=fct_relevel(障碍,“无障碍”,“次要障碍”,“中度障碍”,“主要障碍”)))%>%
ggplot(aes(x=障碍物,y=值,颜色=变量,组=变量))+
连续缩放(打断=缩放::漂亮的打断(n=20))+
geom_线()
graph%>%
#重塑2::熔化(图形,id=“障碍”)%>%
变异(障碍=fct_relevel(障碍,“无障碍”,“次要障碍”,“中度障碍”,“主要障碍”)))%>%
ggplot(aes(x=障碍物,y=值,颜色=变量,组=变量))+
几何线()
连续缩放(打断=缩放::漂亮的打断(n=20))+
比例\颜色\灰色()
在你的第二个ggplot
中,你把fill
和color
混在一起了。设立:
内部color=variable
而不是aes
fill=variable
而不是scale\u color\u gray
scale\u fill\u gray
melt
命令。谢谢江户!这很好,没有融化(我忘了添加代码)。您可以使用tidyr::pivot\u longer
或restrape2::melt
。为了与您的问题更新保持一致,我已经注释掉了重塑
graph %>%
mutate(Obstacle = fct_relevel(Obstacle, "No Obstacle", "Minor Obstacle", "Moderate Obstacle", "Major Obstacle")) %>%
ggplot(aes(x = Obstacle, y=value, colour=variable, group = variable)) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) +
geom_line()
graph %>%
mutate(Obstacle = fct_relevel(Obstacle, "No Obstacle", "Minor Obstacle", "Moderate Obstacle", "Major Obstacle")) %>%
ggplot(aes(x = Obstacle, y=value, fill=variable, group = variable)) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) +
scale_fill_grey() +
geom_line()