I'm assuming that your issue is that + opts(panel.grid.minor = theme_blank()) also gets rid of the horizontal minor lines? Could you convert those to majors and be happy (ie. breaks=seq(0,200,by=25))? If you object to labeling each then you could try supplying labels=c("0","","50","","100","","150")?
Actually this reminds me, sometimes I see a minor_breaks parameter, but I've never been able to get that to work.
https://github.com/hadley/ggplot2/wiki/Graph-Panel-Attributes
--J
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
I messed around trying to do it with geom_hline etc, but this works better:
data <- data.frame(Name = c("A","B","C","D","E","F","G","H"), y = c(100,200,300,400,200,300,400,350))
ggplot(data,aes(x=Name,y=y)) + geom_bar()
grid.remove("panel.grid.minor.x.polyline",grep=T)
grid.remove("panel.grid.major.x.polyline",grep=T)
grid.remove("panel.grid.minor.y.polyline",grep=T)
Note that ggsave seems to discard these edits, so I had to wrap this in png() and dev.off().
Anyone know why ggsave() ignores grid level edits?
I used the instructions here:
https://github.com/hadley/ggplot2/wiki/Editing-raw-grid-objects-from-a-ggplot
Thx,
James
guide_grid <- function(theme, x.minor, x.major, y.minor, y.major) {
ggname("grill", grobTree(
theme_render(theme, "panel.background"),
theme_render(
theme, "panel.grid.minor", name = "y",
x = rep(0:1, length(y.minor)), y = rep(y.minor, each=2),
id.lengths = rep(2, length(y.minor))
),
theme_render(
theme, "panel.grid.major", name = "y",
x = rep(0:1, length(y.major)), y = rep(y.major, each=2),
id.lengths = rep(2, length(y.major))
)
))
}
assignInNamespace("guide_grid", guide_grid, pos="package:ggplot2")
ggplot(mtcars, aes(factor(cyl))) + geom_bar()
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
*digs a little*
Ah, with a fresh R session guide_grid shows the original function, that draws all four (major.x, minor.x, major.y, minor.y), so you cut out the theme_render commands that did the name="x" ones. Nice one.
So this works for swapping back and forth:
#new session
library(ggplot2)
all_guide_grid <- guide_grid
# define new
assignInNamespace("guide_grid", guide_grid, pos="package:ggplot2")
# do stuff
# return to all four
assignInNamespace("guide_grid", all_guide_grid, pos="package:ggplot2")
I suppose then one could write a function like:
theme_choose_grid <- function(x.minor = T, x.major = T, y.minor = T, y.major = T)
which chose which gridlines to display? I tried that but my r-fu is very shonky, failed as early as defining a function in a function ...
--J