Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>An interesting discovery I just made by reading <code>?continuous_scale</code> is that the <code>breaks</code> argument can be:</p> <blockquote> <p>a function, that when called with a single argument, a character vector giving the limits of the scale, returns a character vector specifying which breaks to display.</p> </blockquote> <p>So to guarantee a certain number of breaks, you could do something like:</p> <pre><code>break_setter = function(lims) { return(seq(from=as.numeric(lims[1]), to=as.numeric(lims[2]), length.out=5)) } ggplot(d, aes(x=MW, y=rel.Ki)) + geom_point() + scale_y_log10(breaks=break_setter) </code></pre> <p>Obviously the very simple example function is not very well adapted to the logarithmic nature of the data, but it does show how you could approach this a bit more programmatically.</p> <hr> <p>You can also use <code>pretty</code>, which takes a suggestion for a number of breaks and returns nice round numbers. Using</p> <pre><code>break_setter = function(lims) { return(pretty(x = as.numeric(lims), n = 5)) } </code></pre> <p>yields the following:</p> <p><img src="https://i.stack.imgur.com/38eYq.png" alt="logbreaks"></p> <p>Even better, we can make <code>break_setter()</code> return an appropriate function with whatever <code>n</code> you want and a default of, say, 5.</p> <pre><code>break_setter = function(n = 5) { function(lims) {pretty(x = as.numeric(lims), n = n)} } ggplot(d, aes(x=MW, y=rel.Ki)) + geom_point() + scale_y_log10(breaks=break_setter()) ## 5 breaks as above ggplot(d, aes(x=MW, y=rel.Ki)) + geom_point() + scale_y_log10(breaks=break_setter(20)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload