2

I am using ggplot2 to do some plotting of genomic data, so the basic format is that there is a chromosome and a position along it. I convert the positions to be on a continuous scale, then put the breaks at the boundaries of the chromosomes with:

scale_x_continuous("Genome Position", breaks = c(0, cumsum(chromosome_length)))

That looks great, as far as the actual plotting is concerned, but the labels are then put at the start and end of the chromosomes. I would like them to be centered along each chromosome, at the position where the minor break is drawn by default.

Is this possible?

Quinten
  • 35,235
  • 5
  • 20
  • 53
JAShapiro
  • 196
  • 1
  • 5

1 Answers1

3

How about this?

breaks <- c(0, cumsum(chromosome_length))
scale_x_continuous("Genome Position", breaks = breaks + 0.5, labels = breaks)
hadley
  • 102,019
  • 32
  • 183
  • 245
  • Not so much. Aside from the fact that breaks + 0.5 would not put them in the correct place, this is just moving the major breaks, rather than labeling the minor breaks, which is what I would prefer to do. – JAShapiro Oct 12 '09 at 17:16
  • 1
    Well you can't label the minor breaks, but you can easily simulate the effect by moving the major breaks, adjusting the theme and using geom_vline. Try the ggplot2 mailing list. – hadley Oct 13 '09 at 14:39
  • Impossible labeling the minor ticks: Is this justified or a conceptual bug. At first sight it seems obvious that you want to do that, for example Mayor=years minor=months – Roland Kofler Apr 12 '11 at 12:02
  • 8
    There is an infinite number of things that seems "obvious" to someone - I can only implement and support a finite number – hadley Apr 12 '11 at 17:20
  • 1
    @hadley This would be very useful, though. Plot.ly has added it, and I can't stop using it anymore. – retrography Jul 31 '17 at 13:48
  • I've been searching for such answer for an hour... – Ilona Nov 15 '21 at 13:36