【Bioinfo Blog 002】【R Code 002】【ggplot2 001】geom_boxplot

Introduction

boxplot代码记录
最近发现一个超好用的ggplot2辅助工具包:ggThemeAssist
用shiny交互式的生成想要的样式,一键输出theme的代码,超级超级好用!

放心把ggplot出的图赋值后交给他吧!

ggThemeAssistGadget(p6)

在这里插入图片描述
还有ggsci,我不允许有人不知道它!The Simpsons的调色板莫名好看!!教你用科学杂志喜欢的配色作图——R包ggsci

R Code

library(ggplot2)
library(ggsci)
library(Cairo)

# Set Font from Windows
dev.new()
windowsFonts(HEL=windowsFont("Helvetica CE 55 Roman"),
             RMN=windowsFont("Times New Roman"),
             ARL=windowsFont("Arial"))
             
# Plot and color from ggsci
ggplot(data = mydat[,c("DL","BMIC10A")], 
                  aes(x = factor(BMIC10A), y = DL))+
  geom_boxplot(outlier.size = 1,aes(fill=factor(BMIC10A)),
               position = position_dodge(0.8),size=0.5)+
  scale_fill_npg(labels=c("Normal Weight", "Overweight","Obesity"))+
  labs(fill="Weight Status")+
  scale_x_discrete(labels=c("Normal Weight","Overweight","Obesity"))+
  theme_minimal()+
  theme(axis.text.x=element_text(hjust = 0.5,colour="black",size=12),
        axis.text.y=element_text(family="RMN",size=14),
        axis.title.x=element_text(size=14,vjust = -0.7,family="RMN"),
        axis.title.y=element_text(size=14,vjust = 2,family="RMN"),
        axis.text = element_text(size=12,family="RMN",color="black"),
        panel.background=element_rect(colour="black",fill=NA),
        panel.grid.minor=element_blank(),
        legend.title=element_text(family="RMN", colour="black",size=14),
        legend.text=element_text(family="RMN", colour="black",size=14)
  )+
  ylab("Telomere Length(kbp)")+xlab("10-year-ago BMI") #设置x轴和y轴的标题
 
 # Set dpi and print to PNG
CairoPNG(933,856,file = "boxPlot.png", units = "px",dpi = 300)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值