【问题标题】:Add a smooth line of the average concentration添加平均浓度的平滑线
【发布时间】:2020-12-11 07:43:35
【问题描述】:

我正在尝试在代码中添加平均大小的 geom_smooth 线。

ggplot(data = Birds, 
       aes(Species, size, color=Subject)) +
  geom_line() +
  labs (x = "Species",
        y = "Size(cm)",
        title = "Size and Species of Birds") +
  theme_bw()

【问题讨论】:

  • 你能提供更多关于你所追求的信息吗?有没有可以分享的例子?

标签: r ggplot2 smoothing


【解决方案1】:

这就是你要找的吗?将color=Subject 添加到aes 将为每个主题创建不同的行。因为每个受试者都接受了不同的剂量,但它们是在相同的时间间隔内测量的,所以如果您不根据受试者分割线,绘制 geom_line() 会产生一些奇怪的结果。换句话说,一个 x 值有多个 y 值。

ggplot(data = Theoph, 
       aes(Time, conc)) +
  geom_smooth()+
  #geom_line() +
  geom_point() +
  labs (x = "Time after dose (hours)",
        y = "Theophylline oncentration (mg/L)",
        title = "Theophylline concentration in all subjects over time") +
  coord_equal() +
  theme_bw()

如果您只想要一条干净的平均线,您可以在ggplot“管道”之外执行此操作,然后绘制新的平均线。不过,ggplot 中可能有一种方法可以做到这一切,我只是不知道。

【讨论】:

  • 另外,如果你想保留点的颜色,你可以这样做geom_point(aes(color = Subject)
猜你喜欢
  • 2017-04-24
  • 2021-12-20
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 1970-01-01
  • 2021-12-21
  • 2011-05-13
相关资源
最近更新 更多