ggplot2 - continuous x-scale with large space between y-values: I want to spread out the x-values to visualize y better

Viewed 29

This is a bit hard for me to explain, so please bear with me. I am visualizing methylation data (EPIC array) which contains probes mapped to the genome. These probes are sometimes dense and sometimes sparse.

I want to show the genome position on x and methylation value on y. To see where the probes are in relation to a particular gene, I am making a track plot (fig 1). As you can see there is a large gap with no data in the middle of two clusters of points. I want to show these points better, spread them out, something like in fig 2. However, I can not make x as factor, as it will ruin the scale of the gene in the track plot (they have to align). Im wondering if there is a way to remove this space in the plot, or replace it with a visible break showing that the scale is discontinuous in ggplot? I am aware of facet_zoom, but that doesn´t really work for me with the track plot.

Output track plot

First plot in track plotted with x as factor

My data frame:

head(df) Dataframe

Plot code:

ggplot(df, aes(x = as.numeric(pos), y = beta, col = timepoint)) +
  geom_jitter(width = 0.2, size = 3, alpha = 0.6) +
  labs(title = "CpGs", x = "Chromosome position", y = "Beta value", col = "Day" )+
  scale_color_brewer(palette="PRGn") +
  theme(axis.text.x = element_text(angle = 45)) +
  stat_summary(aes(y = beta, group = timepoint), fun = mean, geom = "line")
0 Answers
Related