[英]How to label specific points in scatterplot
I have a scatterplot using this data.frame
: 我有一个使用此
data.frame
的散点图:
set.seed(1)
df <- data.frame(a=sample(1:10,10), b = sample(1:10,10),ID = sample(letters[1:10]))
I only want to label the points of ID [1:5]
. 我只想标记
ID [1:5]
。
I tried the code below but it still labelled all of them 我尝试了下面的代码,但它仍然标记了所有代码
plot(a~b,data = df)
with(df,text(a~b, labels = ID [1:5]))
I think you just need to subset df in your with()
, try 我认为您只需要在
with()
中将df子集化,请尝试
set.seed(1)
df <- data.frame(a=sample(1:10,10), b = sample(1:10,10),ID = sample(letters[1:10]))
plot(a~b,data = df)
with(df[1:5,], text(a~b, labels = ID [1:5]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.