I'm trying to make a plot with multiple different curves that each have a different linetype with ggplot2 and the lines always show up as solid.
I have tried using linetype = "longdash" and linetype = 6. I have also tried putting the linetype inside and outside the aes() and I've tried using scale_linetype_manual(). Nothing is working currently and every time I try to plot the data, it gives me a solid line. I have also tried updating ggplot2 using install.packages("ggplot2", dependencies = TRUE). I'll include my code below and the plot that I am trying to replicate.
ggplot(simu_dat, aes(tset)) +
geom_line(aes(y = N.simu1), color="plum", linetype = 1, alpha=0.4, linewidth = 4) +
geom_line(aes(y = S.simu1), color="blue4", linetype = 1, alpha=0.4, linewidth = 4) +
geom_line(aes(y = I.simu1), color="deeppink", linetype = 1, alpha=0.4, linewidth = 4) +
geom_line(aes(y = R.simu1), color="springgreen", linetype = 1, alpha=0.4, linewidth = 4) +
geom_line(aes(y = S.simu2), color="blue4", linetype = 6, linewidth = 2) +
geom_line(aes(y = I.simu2), color="deeppink", linetype = 6, linewidth = 2) +
geom_line(aes(y = R.simu2), color="springgreen", linetype = 6, linewidth = 2)
linetype=6
is"twodash"
, andlinetype=5
is"longdash"
. You can look atvignette("ggplot2-specs", package="ggplot2")
to seeHowever, I suggest altering your code to work in a "long format". I don't have your data, but I think this is a good start for pivoting and adapting your code. (I'll show
tidyr::pivot_longer
, though this can be done about as easily withreshape2::melt
and, with more work,stats::reshape
.)or slightly more broken-out