stat_smooth和scale转换的操作顺序 [英] Order of operations for stat_smooth and scale transformation

查看:53
本文介绍了stat_smooth和scale转换的操作顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用重叠的线性拟合线绘制一些对数比例的数据,如下所示:

I'm plotting some log-scaled data with an overlain linear fit line, like so:

d <- data.frame(x=1:10, y=10^(1:10 + rnorm(10)))
ggplot(d, aes(x=x, y=y)) + geom_point() + 
  geom_smooth(method="lm", se=FALSE) +
  scale_y_log10()

看起来 好像是在转换后的数据上计算出线性回归线,否则它将直接经过最后一点.真的吗?

It looks like the linear regression line is being calculated on the transformed data, or else it would go directly through the last point. Is that true?

我似乎记得在 ggplot2 文本中已解决此问题,但现在找不到.

I seem to remember that this is addressed in the ggplot2 text, but I can't find it now.

推荐答案

ggplot 绘制图时,它按以下顺序进行绘制:

When ggplot renders a plot, it does so in the following order:

  1. 将变量映射到美学上(即,针对每一层,找出哪个变量与哪种美学相关联,等等)
  2. 对数据集进行分类(制作面板)
  3. 转换刻度(通常通过任何 scale _ 函数)
  4. 计算美观度(即,在这种情况下,计算 lm 拟合度-这是 stat _ 函数出现的地方,通常通过 geom_函数)
  5. 火车比例尺(弄清楚整个地块的尺寸应该是什么)
  6. 地图比例尺(确定每个图层在整体图中的适合位置)
  7. 渲染几何.
  1. Map variables to aesthetics (ie, for each layer, figure out which variable is associated with which aesthetic, etc.)
  2. Facet the datasets (make panels)
  3. Transform the scales (through any scale_ functions, typically)
  4. Compute the aesthetics (ie, compute the lm fit, in this case -- this is where stat_ functions come in, which are typically called through geom_ functions)
  5. Train scales (figure out what the overall plot dimensions should be)
  6. Map scales (figure out where each layer should fit in the overall plot)
  7. Render geoms.

因此,缩放发生在模型拟合之前,因此是的,拟合是在转换后的数据上计算的.

So, scaling happens before the model is fit, and hence yes, the fit is being calculated on the transformed data.

这篇关于stat_smooth和scale转换的操作顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆