Annotate ggplot with an extra tick and label

后端 未结 2 548
醉梦人生
醉梦人生 2020-12-01 08:24

Can you help me annotate a ggplot2 scatterplot?

To a typical scatter plot (black):

df <- data.frame(x=seq(1:100), y=sort(rexp(100, 2), decreasing         


        
2条回答
  •  天涯浪人
    2020-12-01 08:58

    The following will get you the xyz label and a line above it, you might need to play about with the x and y position for both to get it exactly where you want it.

    ggplot(df, aes(x=x, y=y)) + geom_point() + annotate(x=27, y=0, label="xyz", color="red") +annotate(x=27, ymin=-1, ymax=1, color="red")
    

    More info here if needed.

提交回复
热议问题