New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buffer for text option #1039
Comments
This is do-able, but fiddly because you have to figure out the size of the text at draw time - this means effectively you have to create a custom grid grob. However, I vaguely remember seeing that somewhere, so I'll see it's available. It would also be useful to expose the |
Worth asking the QGIS guys how they do it I'd say. I'll look into it. Cheers. |
I think the right way to tackle this is to develop a new grid grob. Here's a start from Paul Murrell: library(grid)
textbg <- function(t, x, y, col) {
grid.draw(gTree(label = t, x = x, y = y, col = col, cl = "textbg"))
}
#' @export
makeContent.textbg <- function(x, ...) {
tg <- textGrob(x$label, x$x, x$y)
bg <- roundrectGrob(x$x, x$y,
width = grobWidth(tg) + unit(2, "mm"),
height = grobWidth(tg) + unit(2, "mm"),
gp = gpar(
col = NA,
fill = x$col
)
)
setChildren(x, gList(bg, tg))
}
grid.newpage()
textbg("test", .5, .5, "green") I don't have the time to develop it further at the moment. |
Cool. And I don't think I have the skills! Will make time to read the grob section in an attempt to aquire them. Would you recommend this to go into core ggplot2 or an add-on package in the unlikely event that I can do something with this or in the likelier event that someone else can? Will be useful for ggmap. Related question: are there any elements of ggmap that need to adjust to accomodate ggplot2 1.0.0? |
Any updates on this? A halo option for text labels would be useful. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This is a feature request that could make labeling in complex graphics much more aesthetically pleasing: buffers - where you have an area of another colour (typically white) slightly larger than the main text behind the main text to allow the text to be read regardless of what's behind it. This is commonly used in maps, and is implemented to very good effect in QGIS: http://manual.linfiniti.com/en/vector_classification/label_tool.html
The text was updated successfully, but these errors were encountered: