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

R ggplot2 legend with linetypes

$
0
0

I am relatively new to R and I have some difficulties with ggplot2. I have a data frame consisting of three variables (alpha, beta, gamma) and I want to plot them together. I get the plot but I have some problems:

  • (1) legend is outside the plot and I want it to be inside, and
  • (2) linetypes are changed to "solid", "dashed" and "dotted"!

Any ideas/suggestions would be more than welcome!

p <- ggplot() + 
  geom_line(data=my.data,aes(x = time, y = alpha,linetype = 'dashed')) +
  geom_line(data=my.data,aes(x = time, y = beta, linetype = 'dotdash')) +
  geom_line(data=my.data,aes(x = time, y = gamma,linetype = 'twodash')) +
  scale_linetype_discrete(name = "", labels = c("alpha", "beta", "gamma"))+
  theme_bw()+
  xlab('time (years)')+
  ylab('Mean optimal paths')
print(p)

Viewing all articles
Browse latest Browse all 209005

Latest Images

Trending Articles



Latest Images

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