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

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

image.png

(Single cell analysis of cribriform prostate cancer reveals cell intrinsic and tumor microenvironmental pathways of aggressive disease)
我的复现结果(一模一样):

image.png

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


install.packages("waffle")
library(waffle)
library(ggwaffle)
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)))
image.png

也可以设置圆形:


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)))
image.png

好了,这就是今天的内容了,作图数据和注释代码已上传群文件!我又突然想起一个事情,这样的方块图也不仅仅展示样本,还可以作为其他图的注释配合使用,真是不错。感兴趣的探索一下,用在自己文章吧!我的公众号--KS科研分享与服务!

版权声明:
作者:Alex
链接:https://www.techfm.club/p/45720.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>