[R] linetype corruption in ggplot2

Troels Ring tr|ng @end|ng |rom gvdnet@dk
Fri Oct 1 14:52:45 CEST 2021

Dear friends - another simple question: the assignment of linetype seems 
to be corrupted in the code below- I would want the solid line
to be the lowest  and also want the legend to be correct. I guess R 
orders the legend names alphabetically and could handle  that but
cannot unnderstand how the lines apparently are switched.


BB <- cbind(c(1,2,3),c(2,4,6),c(3,6,9))
x <- c(2,3,4)
LT <- c("solid","dashed","dotted")

GG <- ggplot()
for (i in 1:3) {
   dd <- data.frame(x,BB=BB[i,],LT=LT[i])
   GG <- GG + geom_line(data=dd,aes(x=x,y=BB,linetype=LT),size=1)


I'm on Windows, R 4.0.5

All best wishes


More information about the R-help mailing list