欢迎光临散文网 会员登陆 & 注册

ggplot2作图代码——带状图、玫瑰图、森林图、转录组图

2020-05-14 12:13 作者:恶霸小猴子  | 我要投稿

视频记得帮我三连呀,可以帮我更多涨粉滴,哈哈哈,谢谢各位


带状图

# R-code:

> library(ggplot2)

# 设置工作路径到数据存放的文件夹下

> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夹")

# 读数据,数据需要提前整理

> mydata = read.csv("Journal.csv")

> NEJM = read.csv("NEJM.csv")

# 查看数据,良好习惯

> 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)

# 设置工作路径到数据存放的文件夹下

> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夹")

# 读数据,数据需要提前整理

> mydata= read.csv("Population.csv")

# 查看数据,良好习惯

> 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)# 设置工作路径到数据存放的文件夹下

> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夹")

# 读数据,数据需要提前整理

> mydata= read.csv("Tree.csv")

# 查看数据,良好习惯

> 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()

 

 

转录组图

# 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()



ggplot2作图代码——带状图、玫瑰图、森林图、转录组图的评论 (共 条)

分享到微博请遵守国家法律