R 在ggplot中添加正交回归线
我使用以下脚本在R中绘制了一个散点图,比较了预期值和观察值:R 在ggplot中添加正交回归线,r,ggplot2,orthogonal,R,Ggplot2,Orthogonal,我使用以下脚本在R中绘制了一个散点图,比较了预期值和观察值: library(ggplot2) library(dplyr) r<-read_csv("Uni/MSci/Project/DATA/new data sheets/comparisons/for comarison graphs/R Regression/GAcAs.csv") x<-r[1] y<-r[2] ggplot()+geom_point(aes(x=x,y=y))+ scale_size_ar
library(ggplot2)
library(dplyr)
r<-read_csv("Uni/MSci/Project/DATA/new data sheets/comparisons/for comarison
graphs/R Regression/GAcAs.csv")
x<-r[1]
y<-r[2]
ggplot()+geom_point(aes(x=x,y=y))+
scale_size_area() +
xlab("Expected") +
ylab("Observed") +
ggtitle("G - As x Ac")+ xlim(0, 40)+ylim(0, 40)
库(ggplot2)
图书馆(dplyr)
r我不确定我是否完全理解了这个问题,但如果您希望直线段沿x轴和y轴显示错误,可以使用geom_段
执行此操作
大概是这样的:
library(ggplot2)
df <- data.frame(x = rnorm(10), y = rnorm(10), w = rnorm(10, sd=.1))
ggplot(df, aes(x = x, y = y, xend = x, yend = y)) +
geom_point() +
geom_segment(aes(x = x - w, xend = x + w)) +
geom_segment(aes(y = y - w, yend = y + w))
库(ggplot2)
df从这个&这个借来的。基本上,您将需要来自MethComp
的Deming
函数或来自stats
的prcomp
包以及自定义函数perp.segment.coord
。下面是从上面提到的博客文章中选取的一个例子
库(ggplot2)
图书馆(MethComp)
数据(空气质量)
数据24.8083259-0.1906826
#检查prcomp{stats}
r 24.80833
# https://stackoverflow.com/a/30399576/786542
perp.segment.coord似乎不再维护MethComp
包(已从CRAN中删除)。
允许使用stat\u
/geom\u summary
和method=“tls”
添加正交回归线
基于此,我创建了以下函数,允许使用除1以外的噪声比:
我基本上想添加一条回归线,但是我想要正交回归线,而不是线性回归。我不明白这意味着什么。。。若要正交,您肯定需要至少两条直线?这是否回答了您的问题?这是最好的答案-因为它是唯一允许您使用geom_smooth(允许刻面等)的答案
library(ggplot2)
df <- data.frame(x = rnorm(10), y = rnorm(10), w = rnorm(10, sd=.1))
ggplot(df, aes(x = x, y = y, xend = x, yend = y)) +
geom_point() +
geom_segment(aes(x = x - w, xend = x + w)) +
geom_segment(aes(y = y - w, yend = y + w))