如何在散点图中标记特定点

时间:2016-10-20 15:08:57

标签: r plot labels

我有一个使用此set.seed(1) df <- data.frame(a=sample(1:10,10), b = sample(1:10,10),ID = sample(letters[1:10])) 的散点图:

ID [1:5]

我只想标记plot(a~b,data = df) with(df,text(a~b, labels = ID [1:5])) 的分数。

我尝试了下面的代码,但仍然标记了所有代码

var result = filteredLine
        .GroupBy(c => c.Fid)
        .Select(g => new ElmLine()
        {
            Id = g.Key,
            CoordList = g
                .Select(c => { c.CoordX, c.CoordY })
                .Distinct()
                .Select(c => new CoordList() 
                        { XCord = c.CoordX, YCord = c.CoordY })
                .ToList(),
        }).ToList();

2 个答案:

答案 0 :(得分:2)

你可以做到

with(df[df$ID %in% df$ID[c(1:5)],],text(x = b, y = a, labels = ID, pos = 2))

enter image description here

答案 1 :(得分:1)

我认为您只需要在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]))