Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to add points to lines with ggplot2 in R when using ggplot(df)

$
0
0

I am always plotting data.frames.

The style that is fairly easy to use is ggplot(df)+... since one can simply add more geom_lines for additional lines without reshaping/pivoting/melting the source data frame. Notice the help text:

Help Text

df=data.frame(xx=runif(10),yy=runif(10),zz=runif(10))
require(ggplot2)
  ggplot(df) + 
    geom_line(aes(xx,yy, color='yy'))+
    geom_line(aes(xx,zz, color='zz'))+
    ggtitle("Title")

The trouble lies in trying to have the lines have points and have those points appear in the legend. What is the simplest manner to do that?

enter image description here

All answers must pertain to the ggplot(df) methodology...


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>