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

泪湿孤枕 提交于 2019-12-03 01:50:33

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:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!