【发布时间】:2018-08-02 16:29:19
【问题描述】:
我很难为我使用 ggplot2 在 R 中创建的图例添加额外的线型。下面的代码使用变量Percentage.of.Total.Prescriptions.... 和Percentage.Paid.Out.of.Pocket.... 的连续数据来尝试创建具有两组线(实线和虚线)以及各自的图例的线图。
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
第二个代码块创建了一条虚线,我试图在图例中标记它,不幸的是没有运气。
我将不胜感激有关如何向图例添加第二个线型的任何指针,表示虚线。
谢谢
【问题讨论】:
-
我觉得你需要
scale_linetype_xxxggplot2.tidyverse.org/reference/scale_linetype.html -
感谢您的评论,不幸的是,我已经尝试了每个变体,但无法使其正常工作。似乎这些函数不适用于连续数据...