0

What is this type of data visualization plot called and how do I recreate it in R?

Visualization of Answer Frequency in differently sized Bubbles/Circles

Image Source: https://www.pewresearch.org/global/2020/04/30/worldwide-optimism-about-future-of-gender-equality-even-as-many-see-advantages-for-men/pg_2020-04-30_global-gender-equality_0-02/

My Google search only resulted in regular bubble plots like this: https://r-graph-gallery.com/320-the-basis-of-bubble-plot.html

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
marina
  • 11
  • 3
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 04 '23 at 19:33

2 Answers2

2

Here's an example. Lots more formatting tweaks could be done, but I'd think of this fundamentally as a geom_point and a geom_text layer, the rest is tidying up.

library(ggplot2)
fake_data <- data.frame(x = rep(LETTERS[1:3], each = 4),
                        y = letters[1:4],
                        val = (1:12) / 12)

    
ggplot(fake_data, aes(x=1, y = 1, label = scales::percent(val))) +
  geom_point(aes(size = val, color = x), alpha = 0.3) +
  geom_text() + 
  scale_size_area(max_size = 20) +
  guides(size = "none", color = "none") +
  facet_grid(y ~ x, switch = "y") +
  theme_void() +
  theme(strip.text = element_text())

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
2

Something like this?

df <- data.frame(Question = rep(c("Getting\nhigh-paying jobs", 
                                  "Being leaders in\ntheir community",
                                  "Expressing their\npolitical views", 
                                  "Getting a good\neducation"), 3),
                 Answer = rep(c("Men have more\nopportunities",
                                "Women have more\nopportunities",
                                "Both about\nthe same"), each = 4),
                 Value = c(54, 44, 31, 11, 3, 4, 3, 6, 38, 49, 63, 81))

library(ggplot2)

ggplot(df, aes(y    = factor(Question, rev(unique(Question))),
               x    = factor(Answer, unique(Answer)),
               fill = factor(Answer, unique(Answer)))) +
  geom_point(shape = 21, aes(size = Value, color = after_scale(fill))) +
  geom_text(aes(label = Value, color = Answer)) +
  annotate("segment", x = rep(-Inf, 3), xend = rep(Inf, 3),
           y = 1:3 + 0.5, yend = 1:3 + 0.5, linetype = 2, alpha = 0.5) +
  scale_y_discrete() +
  scale_x_discrete(position = "top") +
  scale_size_continuous(range = c(5, 30)) +
  scale_fill_manual(values = c("#959e4a", "#0f6599", "#dddac8")) +
  scale_color_manual(values = c("black", "white", "white")) +
  ggtitle(paste("Many think men have more opportunities than women",
                "when it comes to getting high-paid jobs", sep = "\n")) +
  theme_void() +
  theme(legend.position = "none",
        axis.text.x = element_text(face = 2),
        axis.text.y = element_text(hjust = 1, face = 2),
        plot.margin = margin(30, 30, 30, 30),
        plot.title = element_text(size = 16, face = 2, family = "serif",
                                  margin = margin(20, 0, 50, 0)))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • 1
    lol, yeah I bet the original poster is looking for something like that. But clearly the fonts and line dot sizes need to be updated before this can go to publication. ;-) – Jon Spring Jan 04 '23 at 20:18
  • 1
    most nifty use of `annotate`! – I_O Jan 04 '23 at 21:02
  • Thank you, this is exactly what I was looking for and more! Do you know if there is a specific name for this kind of visualization? Bubble Plot? – marina Jan 05 '23 at 10:21
  • I guess it is _kind of_ a bubble plot with two categorical axes. More like a table with bubble annotations - I don't think I have seen this given a name specifically @marina, though it is quite a nice visualization. – Allan Cameron Jan 05 '23 at 12:51