Home > Back-end >  Tried scale_linetype_manual to add legend but not successful
Tried scale_linetype_manual to add legend but not successful

Time:05-14

Following the thread from enter image description here

Can someone help me with the syntax? Why is it not generating the legend for me?

CodePudding user response:

To get a legend you have to map on an aesthetic, i.e. in your case you have to map on linetype:

library(nlme)
library(ggeffects)
library(ggplot2)

library(ggplot2)
ggplot()  
  geom_line(data = pred.mmlowW, aes(x = x, y = predicted, linetype = "pred.mmlowW"))  
  geom_line(data = pred.mmhighW, aes(x = x, y = predicted, linetype = "pred.mmhighW"))  
  xlim(0.01, 0.2)  
  ylim(30, 150)  
  labs(title = "")  
  ylab(bquote("Total Surface Energy "(mJ / m^2)))  
  xlab(bquote("Surface Coverage "(n / n[m])))  
  theme_minimal()  
  scale_linetype_manual(
    name = "New Legend Title",
    values = c("solid", "dashed"),
    breaks = c(
      "pred.mmlowW",
      "pred.mmhighW"
    ),
    labels = c(
      "wettable soil, 0% relative humidity",
      "water-repellent soil, 0% relative humidity"
    )
  )

  • Related