简体   繁体   中英

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. 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.

You got to set id.n , too. Eg

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

to plot all labels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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