Determining the number of gaps with scales in ggplot2 without conversion?

If I want my data axis to have more gaps, but without converting the values, how can I do this in ggplot2? eg:

... + scale_x_continuous(breaks=scales.trans_breaks("log2", function(x) 2^x, n=8), limits=limits) 

works if you want your data to be converted, and the n= parameter allows you to specify how many gaps. How can you specify breaks without data conversion? Are you just giving it an identification function?

+8
r ggplot2
source share
2 answers

you can give a scale_x_continuous discontinuity vector as follows:

 n=5 breaks = seq(min(dat$x),max(dat$x), length.out = n) m + scale_x_continuous(breaks=breaks) 
+4
source share

I prefer not to give explicit ticks based on calculations in the data, and therefore I want ggplot2 to select ticks for me, considering only the limits and the number of ticks. This code works for me:

  library(scales) scale_x_continuous(breaks = trans_breaks(identity, identity, n = numticks)) 

Of course, you can always set labels explicitly using breaks = ... , as agstudy says.

+15
source share

All Articles