-2

I'm trying to plot Z scores on a y-axis and position on an x-axis. The x-axis is continuous and very long with relatively small areas where z is 'interesting' i.e > 2. I would like to fragment the axis, removing the long areas where Z is not far from 0, then plotting just the immediate area around where Z > 2. Position is 200000 long on my data, and only about 2000 positions have an interesting z-score. Here is what my df looks like;

 Position,Region,Height,Z
 3,orf1,10,0
 4,orf1,10,0.1
 5,orf1,10,0.1
 10,orf2,10,0
 11,orf2,10,-3
 12,orf2,10,-3
 16,orf3,10,0.1
 17,orf3,10,0.1
 18,orf3,10,0.1

 t1 <- ggplot(test, aes(x=Position, y=Z, colour=Z)) +
 geom_point(stat='identity') + ylim(-5,5) + 
 theme(legend.position='none') + scale_x_discrete(limit = c(0,5,8,15))

The axis is still plotted in its entirety. If I want to NOT plot positions 6-10 and 13-15 how do I do this on the x-axis? Thanks

user3062260
  • 1,584
  • 4
  • 25
  • 53
  • I'm not sure what you want to accomplish, but you can also specify the x axis limits by adding `+ xlim(min, max)` or by adding `+ coord_cartesian(xlim = c(min, max))`. – lukeA Feb 13 '15 at 13:27
  • Perhaps my explanation wasn't clear enough. Your suggestions will zoom in on 1 small region only. I need to to zoom in on several small regions spread throughout the data and stitch them together in 1 plot. As I mentioned there are 200,000 positions. I need for example; positions 45-55, 85-95,4500-4550,90000-90050 etc all plotted adjacent to each other. The plotted regions must be continuous in scale, but with breaks in the x-axis between them. – user3062260 Feb 13 '15 at 13:43
  • 1
    What about a facetted plot with free axes, where the facetting variable holds the positions. You should add a [minimum reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to your posting. – lukeA Feb 13 '15 at 13:48
  • Ok, edited as requested. Is the question a bit clearer? – user3062260 Feb 13 '15 at 14:01
  • lukeA, would you mind to post a code example of how to plot a multifacet plot as you describe, each facet plots the entire range of positions rather than just its own position. How do adjust the facet x-axis to position of just 1, the variables are scale and space. – user3062260 Feb 13 '15 at 14:24

1 Answers1

1

Based on lukeA's comment – facetted plot with free x-axis. Drawback is that all subplots have the same size.

require(ggplot2)

d <- read.table("clipboard",sep=",",header=T)
ggplot(d,aes(x=Position,y=Z)) 
  + geom_line() 
  + facet_grid(. ~ region,scales="free_x")

enter image description here

ziggystar
  • 28,410
  • 9
  • 72
  • 124