MariKo
MariKo

Reputation: 305

Change one line in the ggplot graph with scale_linetype_manual

I am trying to change one of the lines in my ggplot from dash to dotted but I fail, the function scale_linetype_manual doesn't do the work. Can anyone help me to solve this problem?

ggplot(d, aes(a,value)) + 
geom_line(aes(color = series), size=2)+
scale_y_continuous(breaks=seq(-2.5, 2.5, 2.5)) +
coord_cartesian(ylim=c(-2.5, 2.5))+
scale_x_continuous(breaks=seq(-200, 2000, 1000)) +
scale_color_manual(values=c("#E69F00","#56B4E9",  "#56B4E9")) +
scale_linetype_manual(values=c("twodash", "dotted", "dotted")) +
theme(legend.direction = 'vertical', 
    legend.position = 'right',
    legend.key = element_rect(size = 7),
    legend.key.size = unit(3, 'lines'))+
theme(panel.grid.major = element_blank(), text = element_text(size=30), 
 panel.grid.minor = element_blank(),
    panel.background = element_blank(), axis.line = element_line(colour = 
 "black"))+
   geom_vline(xintercept=c(0), linetype="dotted", size=1.5)+
 geom_rect(data=rect, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
        color="gray55",
        alpha=0.4,
        inherit.aes = FALSE)+
labs(x = "time [ms]",
   y = "Amplitude [µV]", 
   color = "")

enter image description here

Upvotes: 4

Views: 5161

Answers (1)

markus
markus

Reputation: 26343

The 'problem' with your plot was that you didn't map the aesthetic linetyppe to a variable. Hence, your call to scale_linetype_manual had no effect. You should change your code to be

ggplot(d, aes(a,value)) + 
 geom_line(aes(color = series, linetype = series), size = 2) +
 ...

Upvotes: 6

Related Questions