We can use facet_wrap
to put each chrom
side by side. I used bunch of formatting variables to make the plot look like what you showed above. I also made my own data with two chrom
for better illustration. Look below;
read.table(text="chrom start stop cell_0 cell_1 cell_2
chr1 780000 2920000 2 2 2
chr1 2920000 4920000 1 2 3
chr1 4920000 6920000 2 3 2
chr2 480000 1920000 1 2 3
chr2 1920000 2920000 2 2 2
chr2 2920000 3920000 1 3 3", header=T) -> input
library(ggplot2)
library(tidyr)
input %>%
pivot_longer(c(start,stop)) %>%
ggplot(., aes(x=value, y=as.factor(cell_0), group=1L)) +
geom_point(colour="grey") +
facet_wrap(~chrom, strip.position = "bottom", scales = "free_x") +
geom_line(color = "#00AFBB", size = 1) +
theme_bw() +
theme(panel.spacing.x=unit(0, "lines"),
panel.spacing.y=unit(0, "lines"),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
strip.background = element_rect(color="black", fill="white")) +
scale_x_continuous(expand = c(.01, 0)) +
scale_y_discrete("ploidy", expand = c(.3,.3)) +
ggtitle("cell_596, 2Mb resoloution, mean ploidy 3.04")

Updated solution for the whole data
I added another column to show how this can work for two cell
columns. However, this will be very crowded plot.
# input <- read.table(file = "clipboard", header=T)
## read data from pastebin
library(ggplot2)
library(tidyr)
library(dplyr)
set.seed(123)
input %>%
mutate(cell_1 = cell_0 +
sample.int(1, 1417, replace = T) * sample(c(-1,1),1417, replace = T)) %>%
pivot_longer(c(start,stop), names_to = "step", values_to = "time") %>%
pivot_longer(c(cell_0,cell_1), names_to = "cell", values_to = "ploidy") %>%
ggplot(data=., aes(x=time, y=as.factor(ploidy), group=cell)) +
geom_point(aes(colour=cell)) +
facet_wrap(~chrom, strip.position = "bottom", scales = "free_x", nrow=1) +
geom_line(aes(color = cell), size = 1, alpha=0.5) +
theme_bw() +
scale_x_continuous(expand = c(.01, 0)) +
scale_y_discrete("ploidy", expand = c(.1,.1)) +
theme(panel.spacing.x=unit(0, "lines"),
panel.spacing.y=unit(0, "lines"),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
strip.background = element_rect(color="black", fill="white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5)) +
ggtitle("cell_596, 2Mb resoloution, mean ploidy 3.04")

Final Update:
library(ggplot2)
library(tidyr)
library(dplyr)
library(stringr)
input %>%
pivot_longer(c(start,stop), names_to = "step", values_to = "time") %>%
mutate(chrom = factor(chrom, levels = str_sort(unique(chrom), numeric = T))) %>%
ggplot(data=., aes(x=time, y=as.factor(cell_0), group=1L)) +
geom_point(colour="grey", size=0.5) +
geom_line(color = "#00AFBB", size = 1, alpha=0.5) +
facet_wrap(~as.factor(chrom),
strip.position = "bottom", scales = "free_x", nrow=1) +
theme_bw() +
scale_x_continuous(expand = c(.01, 0)) +
scale_y_discrete("ploidy", expand = c(.1,.1)) +
theme(panel.spacing.x=unit(0, "lines"),panel.spacing.y=unit(0, "lines"),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
strip.background = element_rect(color="black", fill="white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5)) +
ggtitle("cell_596, 2Mb resoloution, mean ploidy 3.04")

Created on 2019-12-10 by the reprex package (v0.3.0)