0

I want to obtain a plot that has a legend. In this legend, it shows the names n, and m which are in the dfRand their associated color. However, I have noticed this works only with groups, which is the case for the iris data set. I could be wrong, which is why I am here.

Any help would be appreciated!

# package:
library(tidyverse)

#df:
dfR<-data.frame(h=rnorm(n=5,mean=4,sd=3),
            m=rnorm(n=5,mean=19,sd=10),
            Z=rnorm(n=5,mean=9,sd=6))




  #Plot:
    p<-ggplot(data=dfR, aes(x=h))+
  labs(title="Title",
       subtitle="Subtitle",
       caption="Run number")+
         geom_line(aes(y=m),color="red")+
         geom_line(aes(y=Z),color="purple")
stefan
  • 90,330
  • 6
  • 25
  • 51
Toy L
  • 55
  • 6
  • Does this answer your question: [Add legend to ggplot2 line plot](https://stackoverflow.com/questions/10349206/add-legend-to-ggplot2-line-plot) – stefan Mar 23 '22 at 23:00
  • (p<-ggplot(data=dfR, aes(x=h))+ labs(title="Title", subtitle="Subtitle", caption="Run number")+ geom_line(aes(y=m,color="m"))+ geom_line(aes(y=Z,color="z"))+ scale_colour_manual(values=c("red","purple"))) – Rfanatic Mar 24 '22 at 09:25

0 Answers0