I am plotting coverage against position, where I have a very simple code like this:
positions <- 1:200000
coverage <- rep(0, length(positions))
coverage[1:200] <- 2000
coverage[30001:30100] <- 5000
coverage[50001:50100] <- 500
coverage[170001:170300] <- 500
cov <- data.frame(position = positions, coverage = coverage)
ggplot(data = cov, aes(x = position, y = coverage)) +
geom_line() +
xlab("Position") +
ylab("Coverage") +
ggtitle("Coverage vs. Position")
This leaves me with something looking like this:
The issue here is that the regions with high coverage are separated by very long tracks of zero coverage. I would like to shorten these regions so that the regions with coverage are visible. For example, cut the x axis when there have been more than 100 consecutive zeros. Is this possible? Thanks in advance!
My approach here is to take the +/- bandwidth average, create a "section" every time the average either becomes or stops being zero, filter out the boring zero sections, leaving views of the areas around the spikes.