一、画箱式图
###加载R包
library(ggpubr)
library(ggplot2)
###加载数据
getwd()
load(file = "D:/BaiduNetdiskDownload/果子生信/Guozi_Maincourse/2021-test/2021.9.24/data/TCGA_steal_data.Rdata")
###加入比较数据,这里是把subgroup列里其他元素和normal比较,将数据储存在my_comparisons中
my_comparisons <- list(
c("Basal", "Normal"), c("Her2", "Normal"),
c("LumA", "Normal",c("LumB","Normal"))
)
###画图,用ggboxplot函数,第一个参数是文件名,设定X轴、Y轴,
ggboxplot(
TCGA_steal_data, x = "subgroup", y = "ESR1",
###颜色分类以subgroup列为准,后面是颜色参数,拿不准可以用帮助文件查看
color = "subgroup", palette = c("aaas"),
###在箱式图上加点
add = "jitter" )+
####后面是增加比较数据并给标尺
stat_compare_means(comparisons = my_comparisons, method = "t.test")
生成的图片
二、画散点图
###加载R包
library(ggpubr)
library(ggplot2)
###加载数据
getwd()
load(file = "D:/BaiduNetdiskDownload/果子生信/Guozi_Maincourse/2021-test/2021.9.24/data/TCGA_steal_data.Rdata")
###画图,用ggboxplot函数,第一个参数是文件名,设定X轴、Y轴,
ggplot(
TCGA_steal_data, aes(x = ESR1, y = BRCA1))+
###颜色分类、形状分类以subgroup列为准
geom_point(aes(color =subgroup, shape =subgroup))+
###设定颜色参数
scale_color_manual(values = c("red", "blue", "orange","violet", "green" ))
结果图
导出结果
## 加载R包
library(export)
## 导成PPT可编辑的格式
graph2ppt(file="dotplot2.pptx")
## 导成AI可以编辑的状态
graph2eps(file="dotplot2.eps")
graph2pdf(file="dotplot2.pdf")
graph2png(file="dotplot2.png")
graph2tif(file="dotplot2.tif")
总结,当函数里参数搞不懂可以复制函数,然后?函数,查看帮助文档,找到所需参数查看使用方法
本图中数据来自果子学生信课程,但里面的代码都是我自己总结注释的,算是学习笔记吧,希望能对大家有所帮助