Simple question: How can I assign custom names AND styles for linetypes of different plots at the same time and print legends.
All plots use library(ggplot2)
.
Example 1: I am able to assign my preferred linetype and plot the legend according to color.
ggplot() +
geom_line(data=data.frame(x=c(0, xv[1]), y=c(0, 1)), aes(x=x, y=y, color = "this one should be dashed"), linetype = "dashed")+
geom_line(data=data.frame(x=c(0, xv[2]), y=c(0, 1)), aes(x=x, y=y, color = "this one should be twodash"), linetype = "twodash")+
geom_line(data=data.frame(x=c(0, xv[3]), y=c(0, 1)), aes(x=x, y=y, color = "this one should be dotted"), linetype = "dotted")+
guides(color = guide_legend("by color"))
Example 2: I am able to assign my preferred linetype but when I try to plot the legend according to linetype no legend shows up.
ggplot() +
geom_line(data=data.frame(x=c(0, 10), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be dashed"), linetype = "dashed")+
geom_line(data=data.frame(x=c(0, 20), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be twodash"), linetype = "twodash")+
geom_line(data=data.frame(x=c(0, 30), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be dotted"), linetype = "dotted")+
guides(linetype = guide_legend("by linetype"))
Example 3: If I use the default linetype without specifying my preferred types I can plot the legend by linetype just fine
ggplot() +
geom_line(data=data.frame(x=c(0, 10), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be dashed"))+
geom_line(data=data.frame(x=c(0, 20), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be twodash"))+
geom_line(data=data.frame(x=c(0, 30), y=c(0, 1)), aes(x=x, y=y, linetype = "this one should be dotted"))+
guides(linetype = guide_legend("by linetype"))