2013-03-14 116 views
4

我想绘制一个U-Pb等时线,它基本上是一个xy图,每个数据点周围有一个错误省略号以指示该数据点的精度。下面是我想要实现的,唯一的区别是,我有更多的数据点的例子:在R中绘制错误省略号

example plot

我有对称的+和 - 在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) 

我该如何去取代带有错误省略号的错误条?

这里是一个Google文档链接到我的数据是.txt格式。

https://docs.google.com/file/d/0B75P9iT4wwlTNUpQand2WVRWV2s/edit?usp=sharing

列是UPbUPbErrP(上UPB误差在1西格玛%),UPbErrAbs(上UPB绝对误差),然后将用于PbPb数据再次相同。

如果你需要我澄清任何事情只是让我知道,我会尽我所能

+2

嗨克里斯,欢迎SO。您发布问题的格式只需要代表其他人的时间和精力即可*将您的数据存入*。相反,请专注于重现您的问题的小型重复性示例。将'dput(head(mydata))'的输出作为代码块粘贴会有所帮助。见[这篇文章](http://stackoverflow.com/q/5963269/1478381)如何使一个伟大的可重复的例子... – 2013-03-14 14:03:38

+1

嗨西蒙,感谢有关礼仪的领导。正如你可以告诉我对R和stackoverflow是全新的,所以我试图尽我所能解释我自己并给出例子和数据集。我会记住dput命令和您为未来发布的链接! – cjms85 2013-03-14 14:31:07

+0

没问题。看看这个答案有多快 - 一个格式正确的问题无法解决。欢迎来到SO的喜悦! – 2013-03-14 14:33:53

回答

7

几月前,我写了一个小功能来绘制椭圆到answer someone else's question。通过简化它,我们可以为您的问题实现一些有用的功能。

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")) 

enter image description here

+0

非常感谢,这就是我一直在寻找的! – cjms85 2013-03-14 14:25:08

+0

嗨!你的代码看起来很棒!你知道是否有一种奇特的方式(如使用ggplot2或Tableu样式)为椭圆内的区域着色? – edwineveningfall 2015-08-27 11:39:36

+0

我认为你可以简单地通过在函数'ellipse'的定义中用'polygon'替换'lines'来做到这一点。 – plannapus 2015-08-27 11:45:02