简体   繁体   English

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

[英]R: scatterplot() from car package, how to add point labels?

I want to scatterplot two variables with point labels (a label for each data point). 我想用点标签(每个数据点的标签)散布两个变量。 One can do this with plot() and textxy() among others, but I like the scatterplot() function from the car package. 可以使用plot()和textxy()来完成此操作,但是我喜欢car包中的scatterplot()函数。 However, I can't figure out how to use it. 但是,我不知道如何使用它。

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

It plots it without errors, but there are no labels. 它打印时没有错误,但是没有标签。

Using textxy() works, but since scatterplot() draws differently than plot() the labels and datapoints are displaced. 使用textxy()可以工作,但是由于scatterplot()绘制的方式与plot()不同,因此标签和数据点被置换了。

You got to set id.n , too. 您还必须设置id.n Eg 例如

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

to plot all labels. 绘制所有标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM