Outlined text with ggplot2

前端 未结 4 727
走了就别回头了
走了就别回头了 2020-12-23 16:55

I\'d like to know if there is a way to draw \"outlined text\" with ggplot2, for example black text with a small white border, in order to make it easily readable on backgrou

4条回答
  •  伪装坚强ぢ
    2020-12-23 17:02

    Not ideal or very flexible but you can get the effect by drawing bold mono text, then standard mono text on top.

    I've used a green panel background to simulate the map.

    d <- diamonds[sample(nrow(diamonds), 10), ]
    
    (p <- ggplot(d, aes(carat, price)) +
      geom_text(
        aes(label = cut, family = "mono", fontface = "bold"), 
        size = 12, 
        colour = "black"
      ) +
      geom_text(
        aes(label = cut, family = "mono"), 
        size = 12, 
        colour = "white"
      ) +
      opts(panel.background = theme_rect(fill = "green"))
    )
    

    text-on-bold-text with the diamonds dataset

提交回复
热议问题