着色一点并在ggplot2中添加注释?

时间:2013-01-16 04:54:12

标签: r dataframe ggplot2

我有一个包含三列的数据框a

GeneNameIndex1Index2

我画了一个像这样的散点图

ggplot(a, aes(log10(Index1+1), Index2)) +geom_point(alpha=1/5)

然后我想为GeneName"G1"的点着色,并在该点附近添加一个文本框,这可能是最简单的方法吗?

2 个答案:

答案 0 :(得分:47)

您可以创建仅包含该点的子集,然后将其添加到绘图中:

# create the subset
g1 <- subset(a, GeneName == "G1")

# plot the data
ggplot(a, aes(log10(Index1+1), Index2)) + geom_point(alpha=1/5) +  # this is the base plot
  geom_point(data=g1, colour="red") +  # this adds a red point
  geom_text(data=g1, label="G1", vjust=1) # this adds a label for the red point

注意:由于每个人都在对这个问题进行投票,我认为我会更容易阅读。

答案 1 :(得分:21)

这样的事情应该有效。您可能需要弄清x的{​​{1}}和y个参数。

geom_text()

screenshot

相关问题