Color one point and add an annotation in ggplot2?

后端 未结 2 893
野的像风
野的像风 2020-12-04 19:58

I have a dataframe a with three columns :

GeneName, Index1, Index2

I draw a scatterplot like this

2条回答
  •  情深已故
    2020-12-04 20:52

    You could create a subset containing just that point and then add it to the plot:

    # 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
    

    NOTE: Since everyone keeps up-voting this question, I thought I would make it easier to read.

提交回复
热议问题