首页 > 解决方案 > 如何更改趋势线的线型(ggplot)

问题描述

我使用以下命令来创建我的图:

AfterLatency <- ggplot(
  After,
  aes(
    x = After$X7.Days.Time.in.Blank,
    y = After$X7.Days.Latency.to.Leave,
    shape = factor(Treatment),
    color = factor(Treatment)
  )
) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  xlab("Time in Blank (s)") +
  ylab("Latency to leave (s)")

我试过这个:AfterLatency + scale_linetype_manual("Treatment", values=c("Control"=2, "Sertraline"=4))

并且还尝试linetype在 geom_smooth 中包含该命令,但均未成功。

我想知道如何将趋势线之一更改为虚线? 在此处输入图像描述

标签: rggplot2

解决方案


尝试添加linetype作为geom_smooth.

geom_smooth(method = 'lm', se = FALSE, aes(linetype = Treatment))

此外,不需要After$. 如果在几何图形中使用其他映射,这很有用。


推荐阅读