提取stat_smooth线拟合的方法 [英] Method to extract stat_smooth line fit
问题描述
有没有办法提取从stat_smooth返回的拟合行的值?
我使用的代码如下所示:
p < - ggplot(df1,aes(x = Days,y = Qty,group = Category,color = Category))
p< - p + stat_smooth(method = glm,fullrange = TRUE)+ geom_point())
用户将不胜感激任何指导。
.htmlrel =noreferrer> stat_smooth
确实会产生您可以在其他地方使用的输出,并且可以通过一个稍微黑客的方式将其放入一个变量在全球环境中。 将输出变量放在 ..
两边以使用它。因此,如果您在 stat_smooth
调用中添加 aes
并使用全局分配,< < -
,将输出分配给全球环境中的变量,您可以获得拟合值或其他值 - 请参阅下面的内容。
[1 ] 1.993594 2.039986 2.087067 2.134889 2.183533 2.232867 2.282897 2.333626
[9] 2.385059 2.437200 2.490053 2.543622 2.597911 2.652852 2.708104 2.764156
[17] 2.821771 2.888224 2.968745 3.049545 3.115893 3.156368 3.175495 3.181411
[25] 3.182252 3.186155 3.201258 3.235698 3.291766 3.353259 3.418409 3.487074
[33] 3.559111 3.634377 3.712729 3.813399 3.910849 3.977051 4.037302 4.091635
[41] 4.140082 4.182676 4.219447 4.250429 4.275654 4.295154 4.308961 4.317108
[49] 4.319626 4.316548 4.308435 4.302276 4.297902 4.292303 4.282505 4.269040
[57] 4.253361 4.235474 4.215385 4.193098 4.168621 4.141957 4.113114 4.08209 6
[65] 4.048910 4.013560 3.976052 3.936392 3.894586 3.850639 3.804557 3.756345
[73] 3.706009 3.653554 3.598987 3.542313 3.483536 3.422664 3.359701 3.294654
您可以获得的输出是: 请注意,默认情况下它会预测80个数据点,这可能与您的原始数据不一致。 Is there a way to extract the values of the fitted line returned from stat_smooth? The code I am using looks like this: This new r user would greatly appreciate any guidance. You enclose the output variable in The outputs you can obtain are: Note that by default it predicts on 80 data points, which may not be aligned with your original data. 这篇关于提取stat_smooth线拟合的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
y
,预测值
ymin
,
平均值下方的点位置置信区间 ymax
,平均值周围的上点点置信区间
se
,标准错误
p <- ggplot(df1, aes(x=Days, y= Qty,group=Category,color=Category))
p <- p + stat_smooth(method=glm, fullrange=TRUE)+ geom_point())
stat_smooth
does produce output that you can use elsewhere, and with a slightly hacky way, you can put it into a variable in the global environment...
on either side to use it. So if you add an aes
in the stat_smooth
call and use the global assign, <<-
, to assign the output to a varible in the global environment you can get the the fitted values, or others - see below.qplot(hp,wt,data=mtcars) + stat_smooth(aes(outfit=fit<<-..y..))
fit
[1] 1.993594 2.039986 2.087067 2.134889 2.183533 2.232867 2.282897 2.333626
[9] 2.385059 2.437200 2.490053 2.543622 2.597911 2.652852 2.708104 2.764156
[17] 2.821771 2.888224 2.968745 3.049545 3.115893 3.156368 3.175495 3.181411
[25] 3.182252 3.186155 3.201258 3.235698 3.291766 3.353259 3.418409 3.487074
[33] 3.559111 3.634377 3.712729 3.813399 3.910849 3.977051 4.037302 4.091635
[41] 4.140082 4.182676 4.219447 4.250429 4.275654 4.295154 4.308961 4.317108
[49] 4.319626 4.316548 4.308435 4.302276 4.297902 4.292303 4.282505 4.269040
[57] 4.253361 4.235474 4.215385 4.193098 4.168621 4.141957 4.113114 4.082096
[65] 4.048910 4.013560 3.976052 3.936392 3.894586 3.850639 3.804557 3.756345
[73] 3.706009 3.653554 3.598987 3.542313 3.483536 3.422664 3.359701 3.294654
y
, predicted valueymin
, lower pointwise confidence interval around
the meanymax
, upper pointwise confidence interval around the mean se
, standard error