Combine the stack and dodge the line in ggplot2

I am trying to recreate this plot without a terrible 3d bar chart and an obscure x axis (these are different time points, and it's hard to say when they are).

Bad plot

(from Science 291, No. 5513 (2001): 2606-8, otherwise good paper.)

My first instinct is to do something similar to what they did, with a 2d-line graph and various x-axis labels, using biased stripes for the genotype and then folded stripes to get a black and white split on the front panels, but a few other good questions here say you can't do this.

, ( ), , , . ? ?

: , , ( m n, -), , .

This is my faceted version.

library(tidyverse)
library(cowplot)

data = tribble(
  ~Timepoint, ~`Ancestral genotype`, ~Mutator, ~`Mean % of auxotrophs`,
  100, 'mutS-', 'o', 10.5,
  150, 'mutS-', 'o', 16,
  220, 'mutS-', 'o', NA,
  300, 'mutS-', 'o', 24.5,
  100, 'mutS+', 'n', 1,
  150, 'mutS+', 'n', NA,
  220, 'mutS+', 'n', 1,
  300, 'mutS+', 'n', 1,
  100, 'mutS+', 'm', 0,
  150, 'mutS+', 'm', NA,
  220, 'mutS+', 'm', 2,
  300, 'mutS+', 'm', 5
)

data <- data %>% mutate(Timepoint = as.character(Timepoint))

data %>% ggplot(aes(x = Timepoint, y = `Mean % of auxotrophs`)) +
  geom_col(aes(fill = Mutator), position = 'stack') + facet_grid(~`Ancestral genotype` ) +
  guides(fill=FALSE)
+4
1

, :

 library(forcats)

 data %>% 
   filter(!is.na(`Mean % of auxotrophs`)) %>%
   ggplot(aes(x = Timepoint, y = `Mean % of auxotrophs`, 
              color = fct_relevel(Mutator, c("o","m","n")), linetype=`Ancestral genotype`)) +
   geom_line() +
   geom_point(size=4) + 
   labs(linetype="Ancestral\ngenotype", colour="Mutator")

enter image description here

: Ancestral genotype . mutS- mutS+ , Timepoint . width, , , . (5.5 5), .

 ggplot() +
   geom_col(data=data %>% filter(`Ancestral genotype`=="mutS+"),
            aes(x = Timepoint + 5.5, y = `Mean % of auxotrophs`, fill=Mutator),
            width=10, colour="grey40", size=0.4) + 
   geom_col(data=data %>% filter(`Ancestral genotype`=="mutS-"),
            aes(x = Timepoint - 5.5, y = `Mean % of auxotrophs`, fill=Mutator), 
            width=10, colour="grey40", size=0.4) + 
   scale_fill_discrete(drop=FALSE) +
   scale_y_continuous(limits=c(0,26), expand=c(0,0)) +
   labs(x="Timepoint")

enter image description here

. , , Timepoint ( , , ), , x , . 3D- - - - 3D-, - , , .

+3

Source: https://habr.com/ru/post/1674319/


All Articles