如何更改趋势线的线型(ggplot)

时间:2018-05-04 01:45:10

标签: r ggplot2

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

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))

并尝试在geom_smooth中包含linetype命令,但都没有工作。

我想知道如何将其中一条趋势线更改为虚线? enter image description here

2 个答案:

答案 0 :(得分:0)

尝试添加linetype作为geom_smooth的审美。

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

此外,不需要After$。如果在geoms中使用其他映射,这很有用。

答案 1 :(得分:0)

首先尝试使用lty作为aesggplot的参数开始:

AfterLatency <- ggplot(
  After,
  aes(
    x = After$X7.Days.Time.in.Blank,
    y = After$X7.Days.Latency.to.Leave,
    shape = factor(Treatment),
    color = factor(Treatment),
    lty=factor(Treatment)
  )
)