花了半天功夫才画出2幅图,用ggplot画图效率低下啊。。
Xnip2020-02-23_19-28-31.jpg Xnip2020-02-23_19-32-57.jpg
library(readxl)
library(stringr)
library(ggplot2)
library(pheatmap)
library(reshape2)
#prepare data
rt <- read.table("m6Aexp.txt",header = T,row.names = 1,sep = "\t")
g <- read_xlsx("ER.xlsx",col_names = T)
colnames(rt) <- substr(colnames(rt),1,12)
class(colnames(rt))
colnames(rt) <- str_replace_all(colnames(rt),"[.]","-")
m <- g$Id %in% colnames(rt)
g <- g[m,]
m2 <- na.omit(match(g$Id,colnames(rt)))
rt <- rt[,m2]
identical(colnames(rt),g$Id)
rt <- as.matrix(rt)
#Heatmap
annotation_col = data.frame(Type = c(rep("ER-", 221), rep("ER+", 987-221)))
rownames(annotation_col) = colnames(rt)
pdf("Heatmap.pdf",width = 7,height = 3)
pheatmap(log(rt),main="TCGA dataset",
fontsize = 10,
scale="row",
annotation_col = annotation_col,
color = colorRampPalette(c("#053061", "white", "firebrick3"))(24),
cluster_rows = F,
cluster_cols = F,
show_colnames = F,
gaps_col = 221,
annotation_colors=list(Type = c(`ER-` = "#43a2ca",
`ER+` = "#f03b20")),
legend = T)
dev.off()
#dotbar plot
df <- as.data.frame(t(rt))
df$group <- factor(annotation_col$Type)
df_p <- melt(df)
pdf("dotbar.pdf",width = 14,height = 6)
p <- ggplot(df_p,aes(x=variable,y=log(value),color=group))+
scale_color_manual(values = c("#43a2ca","#f03b20"))+
geom_point(alpha=0.2,
position = position_jitterdodge(),
size=1)+
geom_boxplot(alpha=0)+
xlab(NULL)+
ylab("Relative mRNA expression")+
scale_y_continuous(expand = c(0, 0))+
theme_bw()
p
dev.off()
#coded by Dk QQ1962369
网友评论