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)