How can you create a box around an axis tick label in ggplot2?

前端 未结 2 1094
梦毁少年i
梦毁少年i 2021-02-05 09:23

For several reasons, I am trying to duplicate the grotesque plot shown below. It violates many precepts of good data visualization so for training purposes my goal is to use

相关标签:
2条回答
  • 2021-02-05 10:04

    Slightly off-topic but this is a suggested quick-and-dirty workaround: export the graph as PNG (bitmapped) or SVG (vector-based) and manually add the black blocks with white text.

    0 讨论(0)
  • 2021-02-05 10:08

    I think your best bet is to create viewports at the location of the tick labels, and draw a black rectangle and white text there. For example:

    vp1 <- viewport(x = 0.225, y = 0.55, width = 0.45, height = 0.07)
    grid.rect(gp = gpar(fill="black"), vp = vp1)
    grid.text("Lack of anti-bribery corruption training or awareness within the business", gp=gpar(col="white", cex = 0.6), vp = vp1)
    

    Will give you the graph below:enter image description here

    0 讨论(0)
提交回复
热议问题