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!

This was a bit of a doozie!
Before you can plot it, you need to figure out how many 0s are in consecutive order.
Then you can plot based on this. Let me be clear I could not find a way to programmatically iterate this.
The final graph will look like