【R作图】R语言GGally画图展示多变量之间两两的相关性
今天给大家介绍一款多变量之间两两的相关性的R包:GGally
组学分析用途: 转录组、蛋白质组还有代谢组等的质量控制,比较样品之间的相关性。
先来个简单的:
# install.packages("GGally")
# install.packages("ggsci") #科研作图的配色
library(GGally)
data(flea)
ggpairs(flea, columns = 2:4)
根据分类进行比较,设置了 color = “Species”:
library(GGally)
library(ggsci)
ggscatmat(data = iris, columns = 1:4,
color = "Species",
alpha = 0.8)+
theme_bw(base_size = 14)+
ggsci::scale_color_aaas()+
theme(plot.title = element_text(hjust = 0.5))
可以自由填充每一个格子里面的东西。这个就考验自己的审美了。
## 先创建一格实例
custom_car <- ggpairs(mtcars[, c("mpg", "wt", "cyl")], upper = "blank", title = "Custom Example")
# 想在其中一格填充一个ggplot图像,先画出来
plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg, label = rownames(mtcars)))
plot <- plot +
ggplot2::geom_text(ggplot2::aes(colour = factor(cyl)), size = 3) +
ggplot2::scale_colour_discrete(l = 40)
# 然后在第一行的第二个格子中填充这个图像
custom\_car[1, 2] <- plot
# 再填一个
personal_plot <- ggally_text(
"ggpairs allows you to put in your own plot. Like that one. <---"
)
custom_car[1, 3] <- personal_plot
custom_car
祝科研顺利,工作顺利。