我可以使用ggplot2做一个气泡图。现在我想聚集一列,然后做泡沫图。我怎样才能做到这一点? 这是情节的样子: 图像看起来像这个
这是我的虚拟数据
x=data.frame(
group=c("A","A","B","B","C","C","C","D","D"),
item=c("apple","pear","apple","peach","orange","cherry","apple","banna","apple"),
count=c(3,5,5,1,9,7,3,2,4))
以下是我的脚本:
library(ggplot2)
xf=x$item
xfu=unique(xf)
x$item=factor(xf,levels=xfu)
p<-ggplot(x)
p + geom_point(aes(x = group, y = item,size= count),las=2,shape=16,
alpha=0.80) +
scale_size_continuous(breaks=c(1,2,3,4,5,6,7,8,9),
labels=c("1","2","3","4","5","6","7","8","9"))+
theme(axis.text.x = element_text(angle = 45, hjust =
1.1,size=11,colour="black",face="bold"),
axis.text.y = element_text(size=11,colour="black"),
axis.title.y = element_text(size=12,colour =
"black",face="bold",vjust=0.12))+
labs(x="",y = "Item")
现在我想对项目数据进行层次聚类,以便获得更明显的模式。项目的顺序并不重要。我怎么能这样做?
答案 0 :(得分:1)
如果您询问如何将气泡放大以重叠,则需要明确设置size=
外 aes()
参数(如下所示)。我已通过geom_text()
电话添加了标签。
如果您希望根据某个顺序将列聚合在一起,则需要连续变量来绘制(需要更多信息来演示)
xf=x$item
xfu=unique(xf)
x$item=factor(xf,levels=xfu)
p<-ggplot(x)
p + geom_point(aes(x = group, y = item), size=15+x$count*7, las=2,shape=21, fill="white", alpha=0.80) +
geom_text(aes(x = group, y = item, label=count), fontface="bold", size=7) +
theme(axis.text.x = element_text(angle = 45, hjust =
1.1,size=11,colour="black",face="bold"),
axis.text.y = element_text(size=11,colour="black"),
axis.title.y = element_text(size=12,colour =
"black",face="bold",vjust=0.12),
panel.grid.major = element_line(linetype = "dashed", size=1, color="black"))+
labs(x="",y = "Item")