r - 具有 geom_smooth 的对数 y

标签 r ggplot2

这个问题类似于这个问题:Use geom_smooth with transformed y

事实上,它是一样的,只是那里提供的解决方案不再有效。

我想要做的是在公式的 y 侧绘制一个具有 log(y) 的 geom_smooth。如果直接在formula做争论,它给出了一个奇怪的结果。因此,我将使用我提到的问题中使用的相同示例:

#This works:
 myplot <- qplot(speed, dist, data=cars)
(myplot + geom_smooth(method="lm", formula=y~log(x)))

#does not work
(myplot + geom_smooth(method="lm", formula=log(y)~x))

#no longer works:
(myplot + geom_smooth(method = "glm", formula = y~x,
                  family = gaussian(link = 'log')))

我所追求的是这样的一行:
myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed)))))

最佳答案

是的,您说得对,似乎必要的语法发生了一些变化:

(myplot + geom_smooth(method = "glm", formula = y~x,
                      method.args = list(family = gaussian(link = 'log'))))

enter image description here

关于r - 具有 geom_smooth 的对数 y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41189823/

相关文章:

r - 使用 coord_fixed 进行多图布局

r - 禁止在R控制台中显示 Shiny 的警告消息

R devtools 不读取包含空格的 Windows 路径,在 $PATH 变量中找不到

r - 如何获得两个向量的交点?

R随机化和随机化数据表的列

r - 如何根据我指定的变量在 ggplot 中排序点

r - 使用 Sankey plot 查看 R ggalluvial 和 ggplot 化妆品中的数据流

r - ggplot2 时间序列绘图 : how to omit periods when there is no data points?

r - 如何在 ggplot geom_smooth() 上使用 manipulate()

r - ggplot2:绘制 2 个变量(线和点)并对齐 2 个图