Expand linetype legend in ggplot2

Viewed 709

I'm showing my data on a timeline with ggplot and I want a different linetype for each treatment. One has a different colour as well, but that shouldn't be relevant.

The problem I have is that the legend only shows a very short part of the line, which makes it difficult to distinguish the linetypes. On some examples I found online, I see longer lines in the legend (e.g. 3-4 dots for lty="dotted"), but I didn't notice anything specific in their code.

How can I change the legend so the linetypes are more clear?

enter image description here

I need a TIFF-file with resolution 600ppi and then it's almost impossible to distinguish. The image I uploaded is with res=100, and here it's more or less okay. With a higher resolution, the lty differences become too small.

Here some dummy code.

library(ggplot2)

# dummy dataset
treat <- rep(c("A","B","C","D"),times=6)
day <- rep(c(0,1,2,3,4,5),each=4)
nr <- sample(5:20,size=24,replace = T)
df <- data.frame(treat,day,nr)

# plot
test <- ggplot(df, aes(day, nr, lty=treat, colour=treat)) + 
  geom_line(size=1.2) +
  scale_linetype_manual(labels=c("A","B","C","D"), values=c("dotted","dotdash","dashed","solid")) +
  scale_colour_manual(labels=c("A","B","C","D"), values=c("black","black","darkgrey","black"))
test

# save as TIFF
tiff('test.tiff', units="in", width=8, height=6, res=600)
test
dev.off()
0 Answers
Related