abline(reg, col="red") > polygon(x= c(X\[order-6ren">
gpt4 book ai didi

r - R 图中的边框

转载 作者:行者123 更新时间:2023-12-04 10:46:15 25 4
gpt4 key购买 nike

对于下面给出的示例,我如何绘制虚线之间的区域?

这是代码:

X <- rnorm(100)
Y<- X + rnorm(100)
reg<-lm(Y~X)

CI <- predict(reg,interval="confidence")
F <- CI[,1]
L <- CI[,2]
U <- CI[,3]

plot(X,F)
abline(reg, col="red")
reg2<-lm(L~X)
abline(reg2, col="red", lty="dashed")
reg3<-lm(U~X)
abline(reg3, col="red", lty="dashed")

这是输出

enter image description here

最佳答案

似乎它应该是重复的,但我在 SO 搜索中找不到它。我知道它在 rhelp 上出现过很多次。但这有一个好运:

require(fortunes)
fortune("every question")

Lastly, by what we could call the 'Liaw-Baron principle', every question that can be
asked has in fact already been asked.
-- Dirk Eddelbuettel (citing Andy Liaw's and Jonathan Baron's opinion on unique
questions on R-help)
R-help (January 2006)

polygon(x= c(X[order(X)], rev(X[order(X)]) ), # both x and y go "out" in order;
y=c(L[order(X)], rev(U[order(X)])), # and then come "back in reverse order
col=rgb(1,0,0,0.3) ) # transparent pink.

> plot(X,Y, pch="+")
> abline(reg, col="red")
> polygon(x= c(X\[order(X)\], rev(X\[order(X)\]) ), y=c(L\[order(X)\],rev(U\[order(X)\])), col=rgb(1,0,0,0.3) )

enter image description here

关于r - R 图中的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14315229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com