使用~1800(R)突出显示图表上的单个数据点

时间:2015-01-06 17:45:47

标签: r data-visualization dataset

我知道我想要的数据行是第1535行。

plot(data.exoplanets$loga, data.exoplanets$logMass, ylab="Log of Mass", xlab="Log of Semi Major Axis")

是我用来绘制初始图形的代码,我已经将loga和logMass分配给数据中的两个不同的列。

我需要突出显示一个并为其添加错误栏。

1 个答案:

答案 0 :(得分:4)

像...一样的东西。

points(data.exoplanets$loga[1535], data.exoplanets$logMass[1535], col="red")

将使用所选颜色重新绘制您的特定点。您可以使用...

添加垂直误差线
lines(rep(data.exoplanets$loga[1535],2), c(lower.error, upper.error), col="red")

这样做是重复x值,以便您绘制垂直线。您需要指定要绘制的上下错误值。

尝试以下操作,看看它在做什么。请注意我使用的pchtype参数。我添加的错误栏比我突出显示的点的值高出和低5%。

x<-0:100                       #creating a vector of x-values
y<-rnorm(length(x), 10, 1)     #creating a vector of y-values

plot(x, y)  #plotting
points(x[10], y[10], col="red", pch=16) #highlighting the tenth point

#and adding error bars around the tenth point
lines(rep(x[10],2), c(y[10]*.95, y[10]*1.05), col="red", type="o", pch="_")