Equivalent ggplot2 alternative to gplots's balloonplot?

Viewed 617

I really like how balloonplot generates the balloon plots with the grid, moreover it keeps the cells with value of zero but does not show the circle. Here is an example,

dt <- as.table(as.matrix(mtcars[1:10,]))
balloonplot(t(dt), xlab ="", ylab="", label = FALSE, show.margins = FALSE, cum.margins=F)

When I tried to generate this in ggplot is a mess, because I can't get the grid to show up correctly and moreover the cells with zero are showing up as dot and not blank.

ggplot(melt(dt), aes(x =X2, y = X1))  +geom_point( aes(size=value),shape=21, colour="black", fill="skyblue")

Is there a way to plot this with ggplot OR alternatively save the gplot as a ggplot object? The reason why I'm I need a ggplot object is because I plan to sticth this as a bigger overall figure with pathwork.

# this fails 
as.ggplot(balloonplot(t(dt), xlab ="", ylab="", label = FALSE, show.margins = FALSE))

thanks!

enter image description here

2 Answers

The closest I could get was the ggpubr balloon plot - does this suit your needs?

library(tidyverse)
#install.packages("ggpubr")
library(ggpubr)

mtcars[1:10,] %>%
ggballoonplot(size.range = c(-0.5,10), rotate.x.text = FALSE,
              ggtheme = theme_minimal(base_size = 14)) +
  ggtitle(label = "Balloon Plot for x by y",
          subtitle = "Area is proportional to Frequency") +
  scale_x_discrete(position='top') +
  theme(panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 14),
        plot.title.position = "plot",
        plot.title = element_text(face = "bold"),
        plot.subtitle = element_text(face = "bold"),
        axis.ticks = element_blank()) +
  geom_tile(color = "black", fill = "transparent")

example_balloon_plot.png

How about this?

library(tidyverse)
dt2 <- as.data.frame(as.matrix(mtcars[1:10,]))

dt2 %>%
  rownames_to_column("Car") %>%
  gather(Variable, Value, -Car) %>%
  ggplot(aes(x = Variable, y = Car, size = Value)) +
  geom_point(colour = "sky blue") +
  scale_size_continuous(range = c(-1, 10)) +
  labs(title = "Balloon Plot for x by y",
     subtitle = "Area is proportional to Freq.",
     x = "",
     y = "") +
  theme_bw()

enter image description here

Related