####ggpubr
library(ggpubr)#load ggpubr
#我的數(shù)據(jù)斜做,這種
p<-ggboxplot(cc,x="style",y="FAT4",color = "group")
p
image.png
image.png
#add grids by the function grids()#
#1、背景虛線
p+grids(linetype="dashed")
#add panel borders lines by the function border()
#2、周圍有框框
p+border("black")
#3腰湾、change background color背景顏色
p+bgcolor("gray")+border("gray")
#4恒削、ggpar改坐標(biāo)鳖谈,標(biāo)簽驱入,表頭等等
p2 <- ggpar(p,
title = "Box plot created with ggpubr",
subtitle = "Length by dose",
caption = "Source: ggpubr",
xlab = "Dose (mg)",
ylab = "Teeth length",
legend.title = "Dose (mg)")
p2#顏色俐载,字體大小
ggpar(p2,
font.title = c(14, "bold.italic", "red"),
font.subtitle = c(10, "orange"),
font.caption = c(10, "orange"),
font.x = c(14, "blue"),
font.y = c(14, "#993333"))
#或者直接用font
p2+
font("title", size = 14, color = "red", face = "bold.italic")+
font("subtitle", size = 10, color = "orange")+
font("caption", size = 10, color = "orange")+
font("xlab", size = 12, color = "blue")+
font("ylab", size = 12, color = "#993333")
##一次性
ggpar(p,
title = "Plot of length \n by dose",#\n是下一段
xlab = "Dose (mg)",
legend.title = "Dose (mg)",
font.title = c(14, "bold.italic", "red"),
font.x = c(14, "bold", "#2E9FDF"),
font.y = c(14, "bold", "#E7B800"))
image.png
#5多矮、圖例位置
ggpar(p,
legend = "right", legend.title = "Dose (mg)")+
font("legend.title", color="blue", face = "bold")+
font("legend.text", color = "red")
#6缓淹、配色
#use custom color palette
ggpar(p, palette = c("#00AFBB", "#E7B800", "#FC4E07"))#palette
#use the ggsci palette
ggpar(p, palette = "npg")#nature#還有jco,常用的學(xué)術(shù)雜志的
#jco color palette
p+color_palette("jco")#還有fill_palette
#first create a scatter plot
#顏色梯度
p3 <- ggscatter(cc, x="style", y="FAT4", color="FAT4", size = 2)
p3
#change the gradient color
#use one custom color塔逃,換顏色?
#gradient_fill差不多
p3+gradient_color("red")
#use two colors
p3+gradient_color(c("blue", "red"))
#use the RColorBrewer palette
p3+gradient_color("RdYlBu")
image.png
#7讯壶、修改坐標(biāo)軸
#change y axis limits
ggpar(p, ylim = c(0, 10))
#change y axis cale to log2
ggpar(p, yscale = "log2")
#format axis scale
ggpar(p, yscale = "log2", format.scale = TRUE)#format.scale=TRUE說(shuō)明y軸刻度也會(huì)scale
image.png
#也可以直接用yscale()
p+yscale("log2", .format = TRUE)
#change the font of x and y axis texts
#rotate x and y texts
p+
font("xy.text", size = 12, color = "blue", face = "bold")+
rotate_x_text(45)+
rotate_y_text(45)
image.png
#remove ticks and axis texts
p+rremove("ticks")+
rremove("axis.text")
#8、修改主題默認(rèn)主題為theme_pubr(),
library(ggthemes)
p+ggthemes::theme_economist()
p <- ggboxplot(ToothGrowth, x="dose", y="len", ggtheme = theme_igray())
p
#移除用rremove
ggdensity(cc,x="style",color = "group",add = "mean", rug = TRUE,
palette = "jco")#雜志jco的配色
sort.val = "asc")#上升排序,區(qū)別于desc湾盗,具體看圖演示
sort.by.groups=TRUE#按組排序 )