0

I am trying to do a simple logged ggplot, showing the change in tree and shrub density over time (site age). the tree species are split into native / exotic.

I have also downloaded the viridis package, to enable a type of coloration to the legend+line+points+confidence interval fill.

The problem is, when I do plot using the viridis code, I get two separate legends, which I don't want. I can't figure out how to keep the viridis legend, and remove the other legend.

I would love to provide a picture of my output - but can't figure out how to add it to this question template...

this is the code I have used:

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)") 
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 1
    I don't get two legends when I try. Do you get some warnings ? You should provide `data.df4` so that we can try with your data. – Stéphane Laurent May 11 '19 at 09:43
  • You don't have two colour scales, you have one colour scale and one fill scale. Deleting `fill = status` from `geom_smooth` should fix your problem. – Richard Telford May 11 '19 at 10:17

1 Answers1

0

Without seeing your data or a screenshot, it's hard to know what needs to change. You can remove legends you don't want in 2 different ways

  • turn off the fill legend ggplot() + guides(fill = FALSE)
  • specify not to create a legend within the layer geom_smooth(..., show.legend = FALSE)

This article can show you how to post some sample data: https://reprex.tidyverse.org/articles/articles/datapasta-reprex.html

yake84
  • 3,004
  • 2
  • 19
  • 35