R语言 绘图 (ggplot2)

本文通过使用R语言及其扩展包ggplot2、gridExtra和RColorBrewer,展示了如何设置工作目录、加载数据文件、定义自定义颜色方案并创建高质量的条形图来展示不同染色体的平均测序深度。此外,还介绍了如何定制图形的主题样式,包括字体、颜色、布局等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

setwd("C:/Users/yuki_cool/RWorkspace")
library(ggplot2)
library(gridExtra) ##多张图片组合为一张图片上
library(RColorBrewer)


mypalette<-brewer.pal(7,"Reds")
paste("aaa","dddd",sep = "")


LSQ_data <-read.table("C:/Users/yuki_cool/RWorkspace/JQL_chr_depth_summary.txt",header = TRUE,sep='\t')


###  主题 样式
windowsFonts(A=windowsFont('等线'), B=windowsFont('微软雅黑'))
par(family='A')
pptblue<-rgb(r=16, g=77, b=96, maxColorValue = 255)
pptgrey<-rgb(r=107, g=107, b=107,maxColorValue = 255)
pptred<-rgb(r=233, g=77, b=96,  maxColorValue = 255)
ppttea<-rgb(r=198, g=96, b=52, maxColorValue = 255)
pptdark<-rgb(r=69, g=87, b=101, maxColorValue = 255)
pptbg<-rgb(r=242, g=242, b=242, maxColorValue = 255)
par(bg=pptbg)
par(bty='l')
par(mar=c(4, 5, 4, 6))

theme<-theme_bw()+theme(legend.position = 'top', #图例位置
                         text=element_text(face = 'bold'), #字体
                         panel.background=element_rect(pptbg), #画布背景颜色
                         plot.background=element_rect(pptbg), #图形背景颜色
                         plot.title = element_text(hjust=0.5,size=16,vjust=0.5), #标题位置
                         panel.border=element_blank(),#图形边界
                         panel.grid.major=element_blank(),#element_line(colour='lightgrey',linetype="dashed"), #网格线
                         panel.grid.minor=element_blank(), #次级网格线
                         legend.title=element_text(size=20, colour='black', vjust=-0.5,face = "bold"), #图例标题
                         legend.text=element_text(size=20, colour='black', face = "bold"), #图例文字
                         legend.background =element_rect(pptbg),#图例背景
                         axis.text=element_text(size=12,colour="black",family='A'), #坐标轴文字
                         strip.text=element_text(size=12,colour="red",family='A'),#分面文字
                         strip.background=element_blank(),#分面的背景
                         axis.line = element_line(size=0.5, colour = 'black'), #轴颜色大小
                         panel.spacing=unit(30,'mm')) #画布大小

#####chromosome depth summary plot
LSQ_dt <- na.omit(data.frame(chrome = LSQ_data$chrome, mean_depth = LSQ_data$chr_depth_sum))



LSQ_plot <- ggplot(LSQ_dt, aes(x = chrome, y = mean_depth))+
  geom_bar(stat = "identity", fill=I(mypalette[1])) + plot_theme+
  labs( y = "Mean depth")


LSQ_plot

# 
# LST_plot <- ggplot(LST_dt, aes(x = chrome, y = mean_depth))+
#   geom_bar(stat = "identity")+ plot_theme +
#   labs( y = "Mean depth")

# ggsave(plot = fushengyi_plot, filename = file.path(local_path, "chr_pic.png"), width = 10, height = 6)
# ####################################
# 
# 
# plot <- ggplot(LSQ_data, aes(depth, qc)) +geom_point(aes(color="LSQ")) +
#   geom_point(data =YZF_data, aes(color="YZF") )+
#   geom_point(data =YZJ_data, aes(color="YZJ"))+
#   geom_point(data =LST_data, aes(color="LST"))+
#   geom_point(data =fushengrong_data, aes(color="FSR"))+
#   geom_point(data =fushengyi_data, aes(color="FSY"))+
#   labs(color="Sample", x = "sequence depth", y = "Fraction of bases (%)", size = 10)
# 
# 
# qc_plot  <- plot + theme_bw() +  plot_theme
#  
#   
# plot1 <- ggplot(LST_data, aes(depth, ac)) +geom_line(aes(color="LST"),size =1.5) +
#     geom_line(data =YZJ_data, aes(color="YZJ"),size =1.5)+
#     geom_line(data =LSQ_data, aes(color="LSQ"),size =1.5)+
#     geom_line(data =YZF_data, aes(color="YZF"),size =1.5)+
#     geom_line(data =fushengrong_data, aes(color="FSR"),size =1.5)+
#     geom_line(data =fushengyi_data, aes(color="FSY"),size =1.5)+
#     labs(color="Sample", x = "cumulative sequence depth", y = "Fraction of bases (%)")
# 
# ac_plot <- plot1+ theme_bw() + plot_theme
# 
# pic<-grid.arrange(qc_plot, ac_plot, ncol = 2)
# 
# 
# ggsave(plot = ac_plot, filename = file.path(local_path, "ac_pic.png"), width = 10, height = 6)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值