我正在尝试绘制一个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)
我如何用错误省略号替换错误栏?
以下是我的数据的Google文档链接,该链接采用.txt格式。
https://docs.google.com/file/d/0B75P9iT4wwlTNUpQand2WVRWV2s/edit?usp=sharing
列为UPb
,UPbErrP
(UPb上的错误为1 sigma%),UPbErrAbs
(UPb上的绝对错误),然后PbPb
再次相同数据
如果您需要我澄清任何事情,请告诉我,我会尽我所能
答案 0 :(得分: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"))