学习小组-day4-Mingwei Guo:R学习
2020-04-20 本文已影响0人
吹不散的烽烟
1.R语言安装
官网下载windows版本
2.Rstudio安装
官网下载windows版本
3.外观设置
12-3
4.学习作图:
1.散点图
plot(rnorm(50))
散点图
2.箱线图
boxplot(iris$Sepal.Length~iris$Species,col = c("lightblue","lightyellow","lightpink"))
箱线图
3.热图
安装加载pheatmap
install.packages("pheatmap")
library(pheatmap)
创建一个矩阵,设置行名为Gene1-20和列名Test1-10
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
创建矩阵
画图
pheatmap(test)
画图
设置kmean数值
pheatmap(test, kmeans_k = 2)
设置kmean数值
进行归一化
pheatmap(test, scale = "row", clustering_distance_rows = "correlation")
进行归一化
修改颜色
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))
修改颜色
修改行或者列聚类
pheatmap(test, cluster_row = FALSE)
修改行或者列聚类
设置图像长宽
pheatmap(test, cellwidth = 15, cellheight = 12, main = "Example heatmap")
设置图像长宽
添加注释
annotation_col = data.frame( CellType = factor(rep(c("CT1", "CT2"), 5)), Time = 1:5)
rownames(annotation_col) = paste("Test", 1:10, sep = "")
annotation_row = data.frame( GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6))))
rownames(annotation_row) = paste("Gene", 1:20, sep = "")
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row)
添加注释
修改行文本角度
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, angle_col = "45")
修改行文本角度
分裂行或列
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14), cutree_col = 2)
分裂行或列
添加想要的行名
labels_row = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "","", "", "Il10", "Il15", "Il1b")
pheatmap(test, annotation_col = annotation_col, labels_row = labels_row)
添加想要的行名
5.基本操作:
R project 管理工作目录
getwd() #查看工作目录
setwd() #设置工作目录
新建一个R project
新建新建成功
显示文件列表
> dir()
[1] "Test.Rproj"
>list.files()
[1] "Test.Rproj"
简单运算
> 1+5
[1] 6
赋值
> a<-666
> a
[1] 666
删除变量
rm(list=ls()) #清空所有变量
历史命令
history()
history()
清空控制台
Ctrl+l