查看原文
其他

R绘图模板——气球图的绘制!

王志山 科研后花园 2023-09-08

 

点击上方

“科研后花园”

关注我们

代码如下:

1、设置工作环境并加载所需R包:

rm(list=ls())#clear Global Environmentsetwd('D:\\气球图')#设置工作路径#加载所需R包library(reshape2) # Flexibly Reshape Data: A Reboot of the Reshape Packagelibrary(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphicslibrary(RColorBrewer) # ColorBrewer Paletteslibrary(grid) # The Grid Graphics Packagelibrary(scales) # Scale Functions for Visualization

2、加载数据并对数据进行处理:

#读取数据df <- read.table(file="Genus.txt",sep="\t",header=T,check.names=FALSE,row.names = 1)#转换数据df$Tax=rownames(df)df1=melt(df)colnames(df1)=c("Tax","Samples","value")

3、绘图并对其进行美化:

#####绘图色生成col <- colorRampPalette(brewer.pal(12,"Paired"))(11)####绘图ggplot()+ geom_point(df1,mapping = aes(x = Samples, y = Tax, size = value, fill=Samples),shape=21)+ scale_fill_manual(values = col)+ scale_size_continuous(range = c(0, 10))+ theme(panel.background = element_blank(), legend.key = element_blank(), axis.text = element_text(color = "black",size = 10), panel.grid.major = element_line(color = "gray"),#网格线条颜色 panel.border = element_rect(color="black",fill=NA))+#边框色 labs(x=NULL,y=NULL)#背景色color <- colorRampPalette(brewer.pal(11,"BrBG"))(30)#添加背景grid.raster(alpha(color, 0.1), width = unit(1, "npc"), height = unit(1,"npc"), interpolate = T)

温馨提示

如果你喜欢本文,请分享到朋友圈,想要获得更多信息,请关注我。





您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存