投稿问答最小化  关闭

万维书刊APP下载

复现NC文章华夫图(方块图)-华丽展示实验样本构成

2022/10/27 14:33:52  阅读:147 发布者:

样本构成是实验的开端,也是后续分析的基础,所以样本信息在论文中需要详细展示,涉及到你实验的真实性和可重复性。一般样本构成可以使用AI做示例图,有些临床采样,可以使用柱状体的方式展示,我们之前讲过一种(复现《nature communications》图表(三):画样本时间轴图(堆叠柱状图))。最近在NC文章中看到用华夫图表示样本的构成,感觉效果很好,这里复现一下。原文图如下:

Single cell analysis of cribriform prostate cancer reveals cell intrinsic and tumor microenvironmental pathways of aggressive disease

我的复现结果(一模一样):

根据原图自己设置一个作图文件,很简单,读入文件加载R包:

install.packages("waffle")

library(waffle)

library(ggplot2)

library(dplyr)

library(tidyverse)

library(reshape2)

library(forcats)

setwd("D:/KS项目/公众号文章/华夫图")

A <- read.csv("华夫图.csv", header = T,

              stringsAsFactors = T,

              fileEncoding = 'GBK')

数据转化、设置因子顺序:

df=melt(A,id="patient")

df$variable <- as.factor(df$variable)

df$variable <- fct_inorder(df$variable)#x轴因子顺序不变

colnames(df)

df$patient <- as.factor(df$patient)

df$patient <- fct_rev(df$patient)#y轴逆序,保持与文章一致

设定对应颜色:

col_group <- setNames(c("#B5C8E8",

                        "#4475C7",

                        "#1A3564",

                        "#F2B900",

                        "#FFE79A",

                        "#CD9AFF",

                        "#00B1F0",

                        "#C6E1B5",

                        "#79B84C"),

                        c('Grade Group2',

                          'Grade Group3',

                          "Grade Group5",

                          "PSA<10ng/ml",

                          "PSA>10ng/ml",

                          "Present",

                          "Absent",

                          "pT3a",

                          "pT3a"))

ggplot结合waffle作图,复刻一模一样:

ggplot(df, aes(variable, patient, fill = value)) +

  geom_waffle()+

  theme(panel.background = element_blank(),

    axis.title = element_blank(),

    axis.ticks = element_blank(),

    legend.title = element_blank(),

    legend.position = "right",

    axis.text.x = element_text(color = 'black',angle = 45,

                               size = 12,hjust = 0,vjust = 0.1),

    axis.text.y = element_text(color = 'black',size = 12))+

  scale_fill_manual("",values = col_group)+

  scale_x_discrete(position = "top")+

  guides(fill = guide_legend(override.aes = list(size=10),

                             label.position ='left',

                             label.theme = element_text(size = 12)))

也可以设置圆形:

ggplot(df, aes(variable, patient, color = value)) +

  geom_waffle(tile_shape='circle', size=8)+

  theme(panel.background = element_blank(),

        axis.title = element_blank(),

        axis.ticks = element_blank(),

        legend.title = element_blank(),

        legend.position = "right",

        axis.text.x = element_text(color = 'black',angle = 45,

                                   size = 12,hjust = 0,vjust = 0.1),

        axis.text.y = element_text(color = 'black',size = 12))+

  scale_color_manual("",values = col_group)+

  scale_x_discrete(position = "top")+

  guides(fill = guide_legend(override.aes = list(size=8),

                             label.position ='left',

                             label.theme = element_text(size = 12)))

好了,这就是今天的内容了

转自:KS科研分享与服务”微信公众号

如有侵权,请联系本站删除!


  • 万维QQ投稿交流群    招募志愿者

    版权所有 Copyright@2009-2015豫ICP证合字09037080号

     纯自助论文投稿平台    E-mail:eshukan@163.com