-1

I want to know how to add a legend to my graph and also if its possible to make a line half solid half dashed. I need the red line to become dashed at 28 and the green one at 20 I've been told to use geo_segment but I can't find a way to see the commands I need to input.

If anyone can help and suggest what codes should I use it would be great.

man<-dataset
ggplot(man,aes(Plot))+
geom_line(aes(y=N),color="forestgreen",lwd=0.5)+
geom_ribbon(aes(ymin=NLB,ymax=NUB),alpha=0.2,fill="green")+
geom_line(aes(y=M),color="navy",lwd=0.5)+
geom_ribbon(aes(ymin=MLB,ymax=MUB),alpha=0.2,fill="blue")+
geom_line(aes(y=S),color="brown1",lwd=0.5)+
geom_ribbon(aes(ymin=SLB,ymax=SUB),alpha=0.2,fill="red")+
xlab("Number of Samples")+
ylab("Number of Diametric-Species")

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Are these points where you want to make the change completely arbitrary? Or is there something in your data itself that indicates if the line should be dashed? – MrFlick Jun 15 '18 at 18:50
  • Hi, the curves are rarefactions and those points are where the extrapolation starts for those curves. so I wanted to make them different to show this. I tried to use the geom_segment command but everytime it gives me an error – Gonzalo de Quesada Jun 15 '18 at 19:03

1 Answers1

0
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
df <- data.frame(
  x = seq(1:200),
  y = log(seq(1:200))
)

df <- df %>% mutate(should_dash = x >= 50)

ggplot(df, aes(x,y)) + geom_line(aes(linetype = should_dash)) 

Created on 2018-06-15 by the reprex package (v0.2.0).

schnee
  • 1,050
  • 2
  • 9
  • 20