添加标签以绘制R中的特定值 [英] Add labels to plot for specific values in R

查看:69
本文介绍了添加标签以绘制R中的特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下数据集创建一个图,我只想为"DisplayName"列中标有T的点添加标签.

I create a plot with the following dataset and I would like to add a label only for points flagged with a T in the "DisplayName" column.

Probe   Name    DisplayName X   Y
bob1    A   0   53.989643   7935.185
bob2    B   T   55.11423    7930.626
bob3    C   0   49.537724   6901.7715
bob4    D   0   57.280113   6687.0156
bob5    E   T   7.5517325   840.3756
bob6    F   0   62.68943    6666.6665
bob7    G   T   32.553364   3036.508
bob8    H   0   34.120102   2553.5354
bob9    I   0   127.54777   7818.89

我的想法是使用text()和which()来添加名称"的值,但我陷入这样的局面:

My idea would be to use text() and which() to add the value of "Name" but I am stuck with something like this:

plot(data$X, data$Y)
text(data$X, data$Y, d$Name[which(d$DisplayName =="T",  arr.ind=TRUE)])

任何帮助将不胜感激,

干杯;)

推荐答案

您可以组合使用subset()with()以仅将部分数据帧用于功能text().

You can combine subset() and with() to use only part of data frame for function text().

plot(df$X, df$Y)
with(subset(df,DisplayName=="T"),text(X,Y,Name))

这篇关于添加标签以绘制R中的特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆