Note that as of ggplot2 2.2.1.9000, the parameter within layout
is changed from panel_ranges
but panel_params
.
The current ggplot (stable) 2.2.1 version uses layout$panel_ranges
the upstream version 2.2.1.9000 on Github now uses layout$panel_params
Example Code and console output below:
Updated ggplot2
require("devtools")
devtools::install_git("git@github.com:tidyverse/ggplot2.git")
data(mtcars)
xbreaks <- c(100, 200, 300)
ybreaks <- c(2, 3, 4, 5)
g <- ggplot(mtcars, aes(hp, wt)) +
scale_x_continuous(breaks=xbreaks) +
scale_y_continuous(breaks=ybreaks) +
geom_point()
b <- ggplot_build(g)
b$layout$panel_ranges[[1]]$x.range
g <- ggplot(mtcars, aes(hp, wt)) +
scale_x_continuous(breaks=xbreaks) +
scale_y_continuous(breaks=ybreaks) +
geom_point()
b <- ggplot_build(g)
b$layout$panel_params[[1]]$x.range
Console Output:
> require("devtools")
Loading required package: devtools
> devtools::install_git("git@github.com:tidyverse/ggplot2.git")
Downloading git repo git@github.com:tidyverse/ggplot2.git
Installing ggplot2
'/usr/local/Cellar/r/3.5.0_1/lib/R/bin/R' --no-site-file --no-environ --no-save \
--no-restore --quiet CMD INSTALL \
'/private/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gp/T/RtmpwOWMNj/filee8386283a116' \
--library='/usr/local/lib/R/3.5/site-library' --install-tests
* installing *source* package ‘ggplot2’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (ggplot2)
Reloading installed ggplot2
> data(mtcars)
> xbreaks <- c(100, 200, 300)
> ybreaks <- c(2, 3, 4, 5)
> g <- ggplot(mtcars, aes(hp, wt)) +
+ scale_x_continuous(breaks=xbreaks) +
+ scale_y_continuous(breaks=ybreaks) +
+ geom_point()
> b <- ggplot_build(g)
> b$layout$panel_ranges[[1]]$x.range
NULL
> g <- ggplot(mtcars, aes(hp, wt)) +
+ scale_x_continuous(breaks=xbreaks) +
+ scale_y_continuous(breaks=ybreaks) +
+ geom_point()
> b <- ggplot_build(g)
> b$layout$panel_params[[1]]$x.range
[1] 37.85 349.15