R:来自汽车包的scatterplot(),如何添加点标签?

时间:2014-08-26 18:19:21

标签: r scatter-plot

我想用点标签(每个数据点的标签)散布两个变量。可以用plot()和textxy()等来做到这一点,但我喜欢car包中的scatterplot()函数。但是,我无法弄清楚如何使用它。

library(car)
test.x = c(1,2,3,4,5,6) #x var data
test.y = test.x*2 #x var data
test.labels = c("a","b","c","d","e","f") #labels
scatterplot(test.y ~ test.x, labels=as.vector(test.labels),smooth=F) #plot

它没有错误地绘制它,但是没有标签。

使用textxy()有效,但由于scatterplot()的绘制方式与plot()不同,因此标签和数据点会被移位。

1 个答案:

答案 0 :(得分:0)

你也必须设置id.n。例如。

scatterplot(test.y ~ test.x, labels=test.labels,smooth=F, id.n = length(test.labels)) 

绘制所有标签。