ggplot2中的geom_path的更改行类型可以
我有一个数据集(下面的一个小摘录),该数据集绘制了三行 - 两行是从一个置信区间的一个模型估计的,第三行是结果的外部确认。
bestFit <- data.frame(Year = c(2006, 2007, 2008,
2006, 2007, 2008,
2006, 2007, 2008),
Estimate = c(4208, 4570, 4925,
0872, 1324, 1193,
6009, 5705, 6474),
Lo95CI = c(2903, 3561, 4036,
0693, 1113, 0999,
NA, NA, NA),
Hi95CI = c(5209, 5453, 5725,
0998, 1489, 1330,
NA, NA, NA),
Reconstruction = c("Abun", "Abun", "Abun",
"Recr", "Recr", "Recr",
"Extl", "Extl", "Extl"))
bestFit$Reconstruction <- factor(bestFit$Reconstruction, ordered = TRUE,
levels = c("Abun", "Recr", "Extl"))
ggplot(aes(y = Estimate, x = Year, fill = Reconstruction), data = bestFit) +
geom_ribbon(aes(ymin = Lo95CI, ymax = Hi95CI,
fill = Reconstruction), alpha = 0.25) +
geom_point(aes(colour = Reconstruction)) +
geom_path(aes(colour = Reconstruction), size = 1) +
scale_x_continuous(breaks = seq(2006, 2008, 2)) +
scale_fill_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
scale_color_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
scale_linetype_manual(values = c("solid", "solid", "dotted"))
我可以手动设置颜色,但是在手动设置行类型时遇到了麻烦。我希望前两条线(来自我的模型)是固体的,第三行(来自外部模型)虚线。
I have a data set (a small excerpt below) that is plotting three lines - two estimated from one model with confidence intervals and a third line that serves as an external confirmation of the results.
bestFit <- data.frame(Year = c(2006, 2007, 2008,
2006, 2007, 2008,
2006, 2007, 2008),
Estimate = c(4208, 4570, 4925,
0872, 1324, 1193,
6009, 5705, 6474),
Lo95CI = c(2903, 3561, 4036,
0693, 1113, 0999,
NA, NA, NA),
Hi95CI = c(5209, 5453, 5725,
0998, 1489, 1330,
NA, NA, NA),
Reconstruction = c("Abun", "Abun", "Abun",
"Recr", "Recr", "Recr",
"Extl", "Extl", "Extl"))
bestFit$Reconstruction <- factor(bestFit$Reconstruction, ordered = TRUE,
levels = c("Abun", "Recr", "Extl"))
ggplot(aes(y = Estimate, x = Year, fill = Reconstruction), data = bestFit) +
geom_ribbon(aes(ymin = Lo95CI, ymax = Hi95CI,
fill = Reconstruction), alpha = 0.25) +
geom_point(aes(colour = Reconstruction)) +
geom_path(aes(colour = Reconstruction), size = 1) +
scale_x_continuous(breaks = seq(2006, 2008, 2)) +
scale_fill_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
scale_color_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
scale_linetype_manual(values = c("solid", "solid", "dotted"))
I can manually set the colors, but am having trouble manually setting the line type. I want the first two lines (which are from my model) to be solid and the third line (which is from an external model) dashed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从评论中:
您尚未映射LineType美学。添加
lineType =重建
在aes
geom_path的一部分
中。From comments:
You haven't mapped the linetype aesthetic. Add
linetype = Reconstruction
inside theaes
portion of yourgeom_path
call.