ggsave png super small text

I'm trying to save a ggplot2 waffle chart using ggsave() but when I use .png (or .jpeg) it produces very small text. When I use .pdf (with all the same code) it looks exactly as I expected. Ideas??

library(tidyverse)
library(janitor)
library(here)
library(waffle)    # install.packages("waffle", repos = "https://cinc.rud.is")
library(RColorBrewer)
library(emojifont)
library(ggforce)
library(packcircles)

# data
d = tribble(
  ~type, ~perc, ~response,
  "First", 18.5, "Yes",
  "First", 100 - 18.5, "No",
  "Second", 33.9, "Yes",
  "Second", 100 - 33.9, "No"
)

ggplot(d, aes(fill = response, values = perc)) + 
  geom_waffle(color = "white", flip = TRUE, make_proportional = TRUE, n_rows = 5) +
  facet_wrap(~type, nrow = 1, strip.position = "bottom") +
  theme_void() + 
  theme(legend.position="right") +
  scale_fill_manual(values = c("#DEEBF7", "#3182BD"), guide = guide_legend(reverse = FALSE)) +
  labs(fill = "") +
  geom_text(data = filter(d, response == "Yes"), x = 3, y = c(2.2, 3.6), aes(label = paste0(perc, "%")),
            size = 8, color = "white") +
  geom_text(data = filter(d, response == "No"), x = 3, y = c(12.6, 14.6), aes(label = paste0(perc, "%")),
            size = 8, color = "dodgerblue4")
ggsave("~/Downloads/fig1.png", width = 5, height = 5, dpi = 300)
2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.