ggplot-绘制GEOM_SMOOTH使用伽马误差分布时的反向y轴
我正在尝试使用伽马错误分布来绘制geom_smooth
。
library(ggplot)
data <- data.frame(x = 1:100, y = (1:100 + runif(1:100, min = 0, max = 50))^2)
p <- ggplot(data, aes(x, y)) +
geom_point() +
geom_smooth(method = 'glm', method.args = list(family = Gamma(link = "log")))
我也想逆转y轴,但是使用scale_y_reverse
,但是这会导致伽马分布失败,因为它不能应用于负值。如何扭转此图的Y轴?
p + scale_y_reverse()
Warning message:
Computation failed in `stat_smooth()`:
non-positive values not allowed for the 'Gamma' family
I am trying to plot a geom_smooth
using a gamma error distribution.
library(ggplot)
data <- data.frame(x = 1:100, y = (1:100 + runif(1:100, min = 0, max = 50))^2)
p <- ggplot(data, aes(x, y)) +
geom_point() +
geom_smooth(method = 'glm', method.args = list(family = Gamma(link = "log")))
I also want to reverse the y-axis however using scale_y_reverse
, but this causes the Gamma distribution to fail as it can't be applied to negative values. How can I reverse the y-axis for this plot?
p + scale_y_reverse()
Warning message:
Computation failed in `stat_smooth()`:
non-positive values not allowed for the 'Gamma' family
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有构建方法可以调用
geom_smooth
的预测值scale> scale_y_reverse
工作。这是可视化回归模型的更传统的方法,即构造,预测和绘图。
I'm not sure if there are build-in methods to call out the predicted values of
geom_smooth
forscale_y_reverse
to work.Here's the more conventional method with visualizing of regression models, i.e. construct, predict and plot.