从文章中重新创建图形

问题描述 投票:0回答:1

我知道这很糟糕,但我真的不知道从哪里开始。我正在尝试重新创建这个人物,但我什至不知道它叫什么。文章没有提及该人物的名称。 X 轴显示按细菌种类分离的个体患者分离株,Y 轴显示 β-内酰胺酶基因。有谁知道它叫什么以及我如何使用 R 重新创建它?

供参考,这是文章:

开放论坛感染疾病。 2019 年 8 月 11 日;6(8):ofz353。 doi:10.1093/ofid/ofz353。 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6736082/

r graph figure
1个回答
0
投票

此设置向您展示了如何在 ggplot 中复制绘图。绘图代码很简单。只需将数据转换为正确的格式即可。

library(ggplot2)

ggplot(df, aes(Patient, genes, fill = species)) +
  geom_tile() +
  scale_fill_manual(values = c('#cd1a77', '#ee4923', '#5370b5', '#10898d'),
                    guide = 'none') +
  coord_cartesian(expand = FALSE) +
  scale_x_continuous(NULL, breaks = 1:100 * 4) +
  ylab(NULL) +
  theme_minimal() +
  theme(panel.background = element_rect(fill = '#c1c1c1', color = NA),
        panel.grid = element_line(linewidth = 0.1),
        axis.text.x = element_blank(),
        axis.text.y = element_text(family = 'serif'))


使用的数据

set.seed(1)

gene <- c("TEM-R164S", "TEM-R164H", "TEM-G238S", "TEM-E104K", "SHV-G238S", 
  "SHV-G238A", "SHV-E240K", "CTX-M-1", "CTX-M-2", "CTX-M-9", "ACC", 
  "ACT/MIR", "CMY II", "CMY/MOX", "DHA", "FOX")

df <- data.frame(Patient = rep(1:400, 2),
                 genes = factor(c(sample(gene, 400, TRUE, 
                                prob = c(1, 1, 1, 1, 20, 1, 2, 20, 1, 10, 1,
                                         1, 1, 1, 1, 1)), rep('', 400)),
                                c('', rev(gene))),
                 species = rep(rep(c('E Coli', 'S Aureus', 'S Pyogenes',
                            'M Tuberculosis'), times = c(240, 120, 16, 24)), 2))
© www.soinside.com 2019 - 2024. All rights reserved.