I am having difficulty adding additional linetypes to the legend for a plot I created in R using ggplot2. The code below uses continuous data for the variables Percentage.of.Total.Prescriptions....
and Percentage.Paid.Out.of.Pocket....
to attempt to create a lineplot with two sets of lines, solid and dashed, and a a respective legend.
Lineplot <- ggplot(Table.6, aes(x = Year,
y = Percentage.of.Total.Prescriptions....,
group = as.factor(Table.6$Insurance.Status),
color = Insurance.Status,
linetype = "Total Insulin \nPrescriptions")) + geom_line()
Lineplot <- Lineplot +
geom_line(aes(y = Percentage.Paid.Out.of.Pocket....,
colour = Insurance.Status,
linetype = "Paid \n Out-of-Pocket"),
linetype = 5)
Lineplot <- Lineplot + labs(title = "Human Insulin Utilization")
Lineplot <- Lineplot + labs(x = "Year")
Lineplot <- Lineplot + labs(y = "Percentage (%)")
Lineplot <- Lineplot + labs(colour = "Insurance Status")
Lineplot <- Lineplot + scale_x_continuous(breaks = c(seq(2002,2015,1)))
Lineplot <- Lineplot + scale_y_continuous(breaks = c(seq(0,1,0.1)))
Lineplot <- Lineplot + expand_limits(y = 0:1)
Lineplot
The second block of code creates a dashed line that I attempt to label in the legend, unfortunately without luck.
I would appreciate any pointers on how to add a second linetype to the legend, representing a dashed line.
Thank you
scale_linetype_xxx
ggplot2.tidyverse.org/reference/scale_linetype.html – Tung