0

我正在尝试做一个简单的记录ggplot,显示树木和灌木密度随时间的变化(站点年龄)。树种分为本地/外来。

我还下载了 viridis 包,为图例+线+点+置信区间填充启用一种着色。

问题是,当我使用 viridis 代码进行绘图时,我得到两个单独的图例,这是我不想要的。我不知道如何保留 viridis 图例,并删除另一个图例。

我很想提供我的输出图片 - 但不知道如何将它添加到这个问题模板中......

这是我使用的代码:

attach(data.df4)
base <- ggplot(data.df4, aes(age, total_trees))

base + 
  theme_classic(base_size = 10, base_family = "times") + 
  scale_y_log10() +
  geom_point(aes(color = status)) +
  geom_smooth(aes(color = status, fill = status), method = "lm", se = TRUE) +
  scale_colour_viridis(discrete = TRUE, option = "D")+
  scale_fill_viridis(discrete = TRUE, option = "D") +
  labs(title = "changes in planted canopy and subcanopy tree and shrub density over time", 
       x = "planting age", 
       y = "density (plot-level)") 
4

1 回答 1

0

如果没有看到您的数据或屏幕截图,很难知道需要更改什么。您可以通过 2 种不同的方式删除您不想要的图例

  • 关闭填充图例ggplot() + guides(fill = FALSE)
  • 指定不在图层内创建图例geom_smooth(..., show.legend = FALSE)

本文可以向您展示如何发布一些示例数据: https ://reprex.tidyverse.org/articles/articles/datapasta-reprex.html

于 2019-05-13T02:27:40.240 回答