use npc units in annotate()

前端 未结 2 626
無奈伤痛
無奈伤痛 2021-01-15 01:38

I have a ggplot object. I would like to add some text with annotate(), and I would like to specify the coordinates of the text in npc units. Is this possible?

2条回答
  •  鱼传尺愫
    2021-01-15 02:16

    As of 'ggpmisc' (>= 0.3.6) the following code works as expected (in CRAN as of 2020-09-10).

    library(ggpmisc)
    p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
    # default justification is "inward"
    p + annotate("text_npc", npcx = 0.8, npcy = 0.75, label = "hello")
    # same justification as default for "geom_text()"
    p + annotate("text_npc", npcx = 0.8, npcy = 0.75, label = "hello",
                 hjust = "center", vjust = "middle")
    

提交回复
热议问题