最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

柱狀圖-腫瘤某一指標的比較和GSVA結(jié)果展示

2022-12-12 10:08 作者:爾云間  | 我要投稿

? ?

本篇將介紹如何利用ggplot2繪制柱狀圖以清楚地展示各腫瘤某一指標的比較(如腫瘤緩解率)和GSVA分析結(jié)果。

?

? ? 1.腫瘤緩解率結(jié)果展示:

首先啟動程序包

library(ggplot2)

然后讀取數(shù)據(jù)

df<-read.csv("easy_input1.csv")

數(shù)據(jù)結(jié)構(gòu)如下圖,為2列。第一列為不同癌癥,第二列為score

按照score排序,并畫圖:

df<-df[order(df$score,decreasing = T),]

df$index<-seq(1,nrow(df))

p<-ggplot(df,aes(x=index,y=score,fill=ID)) +

? geom_bar(stat = 'identity',width = 0.8) +

? scale_fill_brewer(type = "Qualitative", palette = "Paired") + #bar的顏色

?

? scale_y_continuous(breaks=seq(-100, 100, 10), #y軸刻度

?????????????????? ??expand = c(0,0)) + #上下都不留空

? scale_x_discrete(expand = expand_scale(mult = c(0.01,0))) + #左邊留空,右邊到頭

?

? #畫3條橫線

? geom_hline(yintercept = c(-30,0,20),

???????????? linetype = 5, #畫虛線

???????????? size = 0.3) + #線的粗細

?

? #其他主題

? labs(x = "", y = "Maximum Change in Tumor Size (%)",

?????? title = "A Maximum Change in Tumor Size, According to Tumor Type") +

? theme_bw() + #去除背景色

? theme(panel.grid =element_blank()) + #去除網(wǎng)格線

? theme(panel.border = element_blank()) + #去除外層邊框

? theme(axis.line = element_line(colour = "black")) + #沿坐標軸顯示直線

? theme(axis.line.x = element_blank(), axis.ticks.x = element_blank(),

axis.text.x = element_blank()) + #去除x軸

?

? #圖例

? guides(fill = guide_legend(ncol = 5,title = NULL)) + #圖例分5列

? scale_size(range=c(5,20)) +

? theme(legend.background = element_blank(), #移除整體邊框

??????? #圖例的左下角置于繪圖區(qū)域的左下角

??????? legend.position=c(0,0),legend.justification = c(0,0))

??????? #改用下面這行,圖例就會位于頂部

??????? #legend.position="top")

由于Cancer12值很高,使得圖片右側(cè)很空。對其進行修改,讓y軸適合大部分數(shù)據(jù),然后在最高的那個bar上標出實際數(shù)據(jù)

#設置坐標軸范圍,最大值設為50,以適應大多數(shù)數(shù)據(jù)

P <- p + coord_cartesian(ylim = c(-90,50)) + #y軸范圍,根據(jù)實際情況調(diào)整

? #添加數(shù)據(jù)標簽

? geom_text(data = subset(df, score > 50),

??????????? aes(index, 48,label=round(score))) + #在超過50的bar上標出實際數(shù)據(jù)

? geom_text(data = subset(df, index == 3),

??????????? aes(index, score + 1,label = "*")) + #作者的特殊標記

? geom_text(data = subset(df, index == nrow(df)),

??????????? aes(index, score - 3, label = "T"))? #作者的特殊標記

p

2. GSVA結(jié)果展示

2.1 score絕對值小于閾值的bar顯示為灰色

輸入數(shù)據(jù),包含兩列:ID和score

df<-read.csv("easy_input2.csv")

按照score的值分組

df$group<-cut(df$score, breaks = c(-Inf,-4,4,Inf),labels = c(1,2,3))

按照score排序

df<-df[order(df$score,decreasing = F),]

df$index<-seq(1,nrow(df))

開始畫圖:

ggplot(df,aes(x=index,y=score,fill=group)) +

? geom_bar(stat = 'identity',width = 0.8) +

? scale_fill_manual(values = c("palegreen3","snow3","dodgerblue4")) + #bar的顏色

? scale_x_discrete(expand = expand_scale(add = .6)) +

? scale_y_continuous(breaks=seq(-30, 20, 5)) +

? coord_flip() + #坐標軸互換

?

? #畫2條橫線

? geom_hline(yintercept = c(-4,4),

???????????? color="white",

???????????? linetype = 2,#畫虛線

???????????? size = 0.3) + #線的粗細

?

? #寫label

? geom_text(data = subset(df, score > 0),

? aes(x=index, y=0, label=paste0(ID,"? "), color = group),#bar跟坐標軸間留出間隙

??????????? size = 3, #字的大小

??????????? hjust = "inward" ) +? #字的對齊方式

? geom_text(data = subset(df, score < 0),

??????????? aes(x=index, y=0, label=paste0("? ",ID), color = group),

??????????? size = 3, hjust = "outward") +?

? scale_colour_manual(values = c("black","snow3","black")) +

?

? #其他主題

? labs(x = "", y = "t value of GSVA score, tumor \n versus non-malignant",

?????? title = "Endothelial cells, tumour versus non-malignant") +

? theme_bw() + #去除背景色

? theme(panel.grid =element_blank()) + #去除網(wǎng)格線

? theme(panel.border = element_rect(size = 0.6)) + #邊框粗細

? theme(axis.line.y = element_blank(), axis.ticks.y = element_blank(), axis.text.y = element_blank()) + #去除y軸



? guides(fill=FALSE,color=FALSE) ?#不顯示圖例


2.2 pvalue>0.05的bar顯示為灰色

輸入數(shù)據(jù),包含三列,ID、score和pvalue

df<-read.csv("easy_input3.csv")

#按照pvalue分組

df$p.group<-cut(df$pval, breaks = c(-Inf,0.05,Inf),labels = c(1,0))

#按照score分組

df$s.group<-cut(df$score, breaks = c(-Inf,0,Inf),labels = c(0,1))

#合并

df$ps.group <- paste0(df$p.group,df$s.group)

#根據(jù)pvalue和score分為3組

df$group<-ifelse(df$ps.group=='10','1',ifelse(df$ps.group=='11','2','3'))

按照score排序

df<-df[order(df$score,decreasing = F),]

df$index<-seq(1,nrow(df))

開始畫圖:只調(diào)整了顏色順序,其余跟“2.1”的畫圖代碼是一樣的

scale_fill_manual(values = c("palegreen3","dodgerblue4","snow3")) + #顏色


柱狀圖-腫瘤某一指標的比較和GSVA結(jié)果展示的評論 (共 條)

分享到微博請遵守國家法律
宿松县| 哈尔滨市| 台北县| 安丘市| 库尔勒市| 沾化县| 乐山市| 凌云县| 永昌县| 三穗县| 仁怀市| 琼结县| 丰都县| 马山县| 敦煌市| 五家渠市| 义乌市| 北京市| 武陟县| 长泰县| 晋宁县| 于都县| 丰顺县| 大方县| 高密市| 安顺市| 南皮县| 霍林郭勒市| 安乡县| 凌海市| 丁青县| 新建县| 苍南县| 图们市| 奉化市| 安达市| 清丰县| 车致| 合肥市| 小金县| 岳普湖县|