Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的绘制误差椭圆_R_Plot - Fatal编程技术网

R中的绘制误差椭圆

R中的绘制误差椭圆,r,plot,R,Plot,我试图绘制一个U-Pb等时线,基本上是一个xy图,每个数据点周围都有一个误差椭圆,以指示该数据点的精度。下面是我试图实现的一个示例,唯一的区别是我有更多的数据点: 对于x和y空间中的每个数据点,我都有对称的+和-误差,我想用它们来指示误差椭圆的形状 下面是到目前为止我编写的代码。这会绘制出我的数据,但我现在没有错误椭圆,而是有错误条 # Select data file. fname<-file.choose() # Rename imported data file. upbiso &

我试图绘制一个U-Pb等时线,基本上是一个xy图,每个数据点周围都有一个误差椭圆,以指示该数据点的精度。下面是我试图实现的一个示例,唯一的区别是我有更多的数据点:

对于x和y空间中的每个数据点,我都有对称的+和-误差,我想用它们来指示误差椭圆的形状

下面是到目前为止我编写的代码。这会绘制出我的数据,但我现在没有错误椭圆,而是有错误条

# Select data file.
fname<-file.choose()
# Rename imported data file.
upbiso <- read.table(file=fname, header= TRUE)
# Attaches data file as default data source.
attach(upbiso)
# Reads and display column headers in console.
names(upbiso)
# Sets margins around plot.
par(mar=c(5,5,4,2))
# Plots 238U/206Pb vs 207Pb/206Pb with superscript notation for isotopic masses, xlim and ylim sets min and max limit for axes, las rotates y axis labels, cex.lab increases the size of the axis labels.
plot(UPb, PbPb, xlab = expression({}^238*"U/"*{}^206*"Pb"), ylab = expression({}^207*"Pb/"*{}^206*"Pb"), xlim = c(0,2500),ylim = c(0, 1), las=1, cex.lab = 1.5)
# Opens Oceanographic package to run errorbars function and runs 1 sigma percent error bars for x-y co-ordinates.
library(oce)
errorbars(UPb,PbPb,UPbErrP,PbPbErrP, percent=T)
#选择数据文件。

fname几个月前,我写了一个小函数来画椭圆。我认为,只要把它简化一点,我们就可以对你的问题有所帮助

ellipse <- function(a,b,xc,yc,...){
    # a is the length of the axis parallel to the x-axis
    # b is the length of the axis parallel to the y-axis
    # xc and yc are the coordinates of the center of the ellipse
    # ... are any arguments that can be passed to function lines
    t <- seq(0, 2*pi, by=pi/100)
    xt <- xc + a*cos(t)
    yt <- yc + b*sin(t)
    lines(xt,yt,...)
    }

plot(UPb, PbPb, pch=19,
     xlab = expression({}^238*"U/"*{}^206*"Pb"), ylab = expression({}^207*"Pb/"*{}^206*"Pb"), 
     xlim = c(0,2500),ylim = c(0, 1), las=1, cex.lab = 1.5)

apply(upbiso, 1, 
      function(x)ellipse(a=x[2]*x[1]/100, b=x[5]*x[4]/100, 
                               xc=x[1], yc=x[4], col="red"))

ellipse嗨,克里斯,欢迎来到SO。您发布问题的格式需要代表他人花费时间和精力才能获取您的数据。相反,把注意力集中在一个小的可重复的例子上,这个例子会重现你的问题。将
dput(head(mydata))
的输出粘贴为代码块将有所帮助。看看如何制作一个很好的可复制的例子…嗨,西蒙,谢谢你关于礼仪的指导。正如你所知道的,我对R和stackoverflow完全陌生,所以我尽力解释自己,并给出示例和数据集。我会记住dput命令和你为将来发布的链接!没问题。看看回答得有多快——一个格式正确的问题没有止境。欢迎来到欢乐的SO!非常感谢,这正是我想要的!你好你的代码看起来很棒!你知道有没有一种奇特的方法(如ggplot2或Tableu样式)来给椭圆内的区域上色吗?我想你只需在函数
椭圆的定义中将
线
替换为
多边形
。我在这里找到了一个很好的答案: