Add geom_text to waffle chart with ggplot2

214 Views Asked by At

With the following code, I used waffle package to generate a waffle chart

library(tidyverse)
library(waffle)
df <- structure(list(
  parts = c("case_1", "case_2", "case_3"),
  values = c(11, 34, 55)
),
row.names = c(NA, -3L),
class = c("tbl_df", "tbl", "data.frame")
)

df
p <- df %>% ggplot() +
  geom_pictogram(
    n_rows = 10, aes(label = parts, values = values, color = parts),
    family = "FontAwesome5Free-Solid",
    flip = TRUE,
    size = 10
  ) +
  scale_label_pictogram(
      name = "Cases", values = c("male"),
  ) +
  scale_color_manual(
      name = "Cases", 
      values = c("case_1" = "red", "case_2" = "green", "case_3" = "grey85"
    )
  ) +
  coord_equal() +
  theme_minimal() +
  theme(legend.position = "bottom")
p

Then, I tried to add "45%" to the chart with geom_text. However, it did not show "45%" but the icon instead like this:

p + geom_text(aes(x = 5, y = 7, label = "45%"),
  size = 24,
  show.legend = FALSE
)

enter image description here

0

There are 0 best solutions below