Home > Blockchain >  How to visualize frequency of a survey answer with circles/bubbles of different sizes in R
How to visualize frequency of a survey answer with circles/bubbles of different sizes in R

Time:01-05

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: enter image description here

CodePudding user response:

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

  • Related