Skip to content

Buffer for text option #1039

Closed
Closed

Description

@Robinlovelace

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

Activity

  1. hadley commented on Jun 11, 2015

    @hadley
    Member

    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 check.overlap argument - it's not perfect (since you can't control what gets removed) but it might be helpful in some situations.

  2. Robinlovelace commented on Jun 11, 2015

    @Robinlovelace
    Author

    Worth asking the QGIS guys how they do it I'd say. I'll look into it. Cheers.

  3. hadley commented on Jun 15, 2015

    @hadley
    Member

    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.

  4. Robinlovelace commented on Jun 15, 2015

    @Robinlovelace
    Author

    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?

  5. t-kalinowski commented on Mar 12, 2018

    @t-kalinowski
    Contributor

    Any updates on this? A halo option for text labels would be useful.

  6. lock commented on Sep 8, 2018

    @lock

    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/

  7. locked and limited conversation to collaborators on Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions