ggplot2 - R-style axes with ggplot -
using ggplot, possible "r-style" x/y axes don't meet @ origin , instead consist of 2 disconnected ranges, in following example?
the reason here ggplot plots consistent next pure-r ones.
try this,
library(ggplot2) d <- data.frame(x=1:10, y=rnorm(10)) base_breaks_x <- function(x){ b <- pretty(x) d <- data.frame(y=-inf, yend=-inf, x=min(b), xend=max(b)) list(geom_segment(data=d, aes(x=x, y=y, xend=xend, yend=yend), inherit.aes=false), scale_x_continuous(breaks=b)) } base_breaks_y <- function(x){ b <- pretty(x) d <- data.frame(x=-inf, xend=-inf, y=min(b), yend=max(b)) list(geom_segment(data=d, aes(x=x, y=y, xend=xend, yend=yend), inherit.aes=false), scale_y_continuous(breaks=b)) } ggplot(d, aes(x,y)) + geom_point() + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + base_breaks_x(d$x) + base_breaks_y(d$y)
edit: related issue has since been discussed in ggtheme package, , potentially provides cleaner solution (no need provide data explicitly breaks function).
Comments
Post a Comment