Recreating a figure from an article

39 Views Asked by At

I know this is poor form, but I really don't know where to start. I'm trying to re-create this figure but I don't even know what it's called. The article doesn't mention what the figure is called. The X-axis shows individual patient isolates, segregated by bacterial species and the Y-axis shows the beta-lactamase genes. Does anyone know what it's called and how I could recreate it using R?

For reference, this is the article:

Open Forum Infect Dis. 2019 Aug 11;6(8):ofz353. doi: 10.1093/ofid/ofz353. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6736082/

Figure 1 from article

1

There are 1 best solutions below

0
Allan Cameron On

This code allows you to replicate the plot in ggplot.

library(ggplot2)

ggplot(df, aes(Patient, genes, fill = species)) +
  geom_tile() +
  scale_fill_manual(values = c('#cd1a77', '#10898d', '#ee4923', '#5370b5'),
                    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'))

enter image description here

The issue is that this code only works because I created the data set in the correct format to plot it. We have no idea if your data is in the same format or not, so can't easily advise other than to make your question reproducible.


Data used

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