R gplots和x27的等效ggplot2替代方案;气球阴谋?

R gplots和x27的等效ggplot2替代方案;气球阴谋?,r,ggplot2,gplots,R,Ggplot2,Gplots,我非常喜欢BallooPlot如何使用网格生成气球图,而且它保持单元格的值为零,但不显示圆。举个例子, dt <- as.table(as.matrix(mtcars[1:10,])) balloonplot(t(dt), xlab ="", ylab="", label = FALSE, show.margins = FALSE, cum.margins=F) 有没有办法用ggplot来打印此内容,或者将gplot另存为ggplot对象?我之所以

我非常喜欢BallooPlot如何使用网格生成气球图,而且它保持单元格的值为零,但不显示圆。举个例子,

dt <- as.table(as.matrix(mtcars[1:10,]))
balloonplot(t(dt), xlab ="", ylab="", label = FALSE, show.margins = FALSE, cum.margins=F)
有没有办法用ggplot来打印此内容,或者将gplot另存为ggplot对象?我之所以需要一个ggplot对象,是因为我计划用pathwork将其作为一个更大的整体图形

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


我能得到的最接近的是ggpubr气球图-这适合你的需要吗

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")
这个怎么样

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()
库(tidyverse)
dt2%
行名到列(“Car”)%>%
聚集(变量,值,-Car)%>%
ggplot(aes(x=变量,y=车辆,尺寸=值))+
几何点(颜色=“天蓝色”)+
刻度大小连续(范围=c(-1,10))+
实验室(title=“x by y的气球图”,
subtitle=“面积与频率成比例”,
x=“”,
y=“”)+
主题_bw()

谢谢,我也有类似的东西,我在两层中绘制它,第一层将alpha设置为0,但是出现了相同的情况,网格线与圆相交,而不是像BalloodPlot那样围绕圆。@Ahdee我明白你的意思了。要使零单元格为空而不是零,只需将大小刻度的下端设为负数,如下所示:scale\u size\u continuous(range=c(-1,10))。这将解决您的一个问题。
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()