Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlined letters in text ggplot2 - 538 style

Tags:

r

ggplot2

Does anyone know whether it’s possible to replicate in ggplot2 538’s feature of outlining text in a plot?

In the example attached. Would it be possible to add the rounded white outline to the percentage?

enter image description here

like image 856
PabloAB Avatar asked Nov 17 '25 19:11

PabloAB


1 Answers

One option would be the shadowtext package and a second one would be ggrepel:

library(ggplot2)
library(shadowtext)

df <- data.frame(
  x = factor(1),
  y = factor(1),
  label = "78%"
)
ggplot(df, aes(x = x, y = y, label = label)) +
  geom_tile(fill = "firebrick") +
  geom_shadowtext(color = "black", size = 14 / .pt, fontface = "bold", bg.colour = "white", bg.r = .2) +
  theme_void()

library(ggrepel)

ggplot(df, aes(x = x, y = y, label = label)) +
  geom_tile(fill = "firebrick") +
  geom_text_repel(color = "black", size = 14 / .pt, fontface = "bold", bg.colour = "white", bg.r = .2, force = 0) +
  theme_void()

like image 91
stefan Avatar answered Nov 19 '25 10:11

stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!