ggplot2作圖代碼——帶狀圖、玫瑰圖、森林圖、轉(zhuǎn)錄組圖

視頻記得幫我三連呀,可以幫我更多漲粉滴,哈哈哈,謝謝各位

帶狀圖
# R-code:
> library(ggplot2)
# 設(shè)置工作路徑到數(shù)據(jù)存放的文件夾下
> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夾")
# 讀數(shù)據(jù),數(shù)據(jù)需要提前整理
> mydata = read.csv("Journal.csv")
> NEJM = read.csv("NEJM.csv")
# 查看數(shù)據(jù),良好習(xí)慣
> mydata
> head(mydata)
> dim(mydata)
# 作圖
> ggplot(data = NEJM) +
????aes(x = Year, y = IF) +
????geom_line(color = "black",size = 1.5) +
????geom_ribbon(data = mydata, aes(ymin =
?????????????min, ymax = max), alpha = .2)+
????geom_line(data = mydata, aes(color =
???????????Journal), alpha = .2, size = 1)+
????geom_hline(yintercept = 10, color =
????????"darkgrey", size=0.5,linetype = 2)+
????geom_vline(xintercept = 2017) +
????annotate(geom = "text", x = 2016.5, y =
?????????90, label ="制高點", angle = 90) +
????labs(title = "知名期刊影響因子變化趨勢",
????subtitle = "B站up主:小猴子_愛你呀呀")+
????theme_bw()
?
?
玫瑰圖
# R-code:
> library(ggplot2)
# 設(shè)置工作路徑到數(shù)據(jù)存放的文件夾下
> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夾")
# 讀數(shù)據(jù),數(shù)據(jù)需要提前整理
> mydata= read.csv("Population.csv")
# 查看數(shù)據(jù),良好習(xí)慣
> mydata
# 作圖
> ggplot(data = mydata) +
????aes(x = sample, y = aged) +
????geom_col(aes(fill = sample),width= 1)+
????scale_fill_viridis()+
????geom_col(aes(y = 15),fill="white",width
?????????????= 1,alpha = 0.5)+
????geom_col(aes(y = 13),fill="white",width
?????????????= 1)+
????coord_polar() +
theme_void()
?
森林圖
# R-code:
> library(ggplot2)# 設(shè)置工作路徑到數(shù)據(jù)存放的文件夾下
> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夾")
# 讀數(shù)據(jù),數(shù)據(jù)需要提前整理
> mydata= read.csv("Tree.csv")
# 查看數(shù)據(jù),良好習(xí)慣
> mydata
> head(mydata)
> dim(mydata)
# 作圖
> ggplot(data = mydata) +
????aes(x = HR, y = id) +
????geom_errorbarh(aes(xmax = HR95H, xmin =
????HR95L),color="black",height=0,size=0.8)+
????geom_point(size = 4, shape = 18,
???????????????aes(color = pvalue)) +
????geom_vline(xintercept = 1, linetype =
???????????????"dashed", size= 1.2) +
????coord_trans(x='log2') +
????scale_x_continuous(breaks = c(0.2,0.5,
???????????????????????1,1.5, 2, 3, 5, 7))+
????labs(x = "Hazard ratios", y =
??????"Classification", color = "p value")+
????theme_bw()
?
?
轉(zhuǎn)錄組圖
# R-code:
> library(ggplot2)
> ggplot(data = diamonds) +
????aes(x = carat, y = price) +
????geom_jitter(size = 0.7, aes(color =
????????????????color)) +
????geom_smooth(color = "grey30") +
????facet_wrap(~ clarity,scales ="free_y")+
????annotate("ribbon", x = c(0, 5),
?????????????ymin = 10000, ymax = 15000,
?????????????alpha = .1, fill = "blue") +
????geom_hline(yintercept = c(10000,15000),
???????????????linetype = "dotted") +
????geom_hline(yintercept = c(12500),
???????????????linetype = "dashed") +
????scale_color_brewer(palette = "Paired")+
????labs(x = "", y = "Expression Level",
?????????color = "") +
????theme_bw()
