如何使用GGPlot绘制两条虚线虚线

塔里格335

我目前正在尝试使用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))

我觉得我缺少一种简单的输入。谢谢。

内森

您需要做的是使用scale_linetype_manual(),然后告诉它两个治疗组都需要一个虚线。

让我们从一个可复制的示例开始:

# reproducible example:
set.seed(0)
time <- rep(1:100,2)
treatment <- c(rep("A",100), rep("B",100))
mean_heartrate <- c(rnorm(100,60,2), rnorm(100,80,2))

coli_means <- data.frame(time, treatment, mean_heartrate)

# ggplot
coli_means  %>% 
  ggplot(aes(x = time, y = mean_heartrate)) + 
  geom_point(aes(color = treatment)) + 
  geom_smooth(aes(linetype = treatment, color = treatment))+
  scale_linetype_manual(values = c('dashed','dashed'))

[两种疗法的虚线

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章