【发布时间】:2019-11-12 05:19:52
【问题描述】:
我目前正在使用 ggplot 函数尝试两条虚线。该图显示了属于两个不同因子组的两条回归线。我已经能够使其中一条线变成虚线,但是我无法让另一条线变成虚线。任何帮助将不胜感激。
coli_means %>%
ggplot(aes(time, mean_heartrate, group = treatment)) +
geom_point( aes(group = treatment, color = treatment)) +
geom_smooth(aes(method = "loess", linetype = treatment, se = FALSE,
group = treatment, color = treatment, show.legend = TRUE))
我觉得我缺少一个简单的输入。谢谢。
【问题讨论】:
-
1) 如果您反复使用
color和group,请将它们放在对ggplot的原始调用中,然后从其他任何地方删除它们。 2)然后就做geom_smooth(method = "loess", linetype = "dashed", se = FALSE, show.legend = TRUE) -
为了扩展@RuiBarradas 的评论,如果
linetype = …在aes()中,它指的是一种分解数据的方法(即aes(linetype=treatment)将分配列处理中不同因素的不同线型)如果它在aes()之外外部它将更改该层创建的所有线的线型,无论它们的组/因素如何
标签: r ggplot2 rstudio regression