How to make geom_text plot within the canvas's bounds

前端 未结 4 1202
无人及你
无人及你 2020-11-29 03:55

Using geom_text to label outlying points of scatter plot. By definition, these points tend to be close to the canvas edges: there is usually at least one word that overlaps

4条回答
  •  被撕碎了的回忆
    2020-11-29 04:22

    You can turn off clipping. For your example it works just great.

    p <- ggplot(data=df, aes(x=n.wheels, y=utility, label=word))  + geom_text() 
    gt <- ggplot_gtable(ggplot_build(p))
    gt$layout$clip[gt$layout$name == "panel"] <- "off"
    grid::grid.draw(gt)
    

    Clipping off

提交回复
热议问题