Permalink
Browse files

Add independent control of x and y gridlines

  • Loading branch information...
1 parent d4f4390 commit ce9746ab0cd00cb87880ddf923a9e8491ea409a6 @wch wch committed May 27, 2012
Showing with 15 additions and 9 deletions.
  1. +2 −2 R/coord-map.r
  2. +9 −3 R/coord-polar.r
  3. +4 −4 R/guides-grid.r
View
@@ -151,7 +151,7 @@ coord_render_bg.map <- function(coord, details, theme) {
if (nrow(xlines) > 0) {
grob.xlines <- element_render(
- theme, "panel.grid.major", name = "x",
+ theme, "panel.grid.major.x",
xlines$x, xlines$y, default.units = "native"
)
} else {
@@ -160,7 +160,7 @@ coord_render_bg.map <- function(coord, details, theme) {
if (nrow(ylines) > 0) {
grob.ylines <- element_render(
- theme, "panel.grid.major", name = "y",
+ theme, "panel.grid.major.y",
ylines$x, ylines$y, default.units = "native"
)
} else {
View
@@ -192,25 +192,31 @@ coord_render_bg.polar <- function(coord, details, theme) {
r <- 0.4
rfine <- c(r_rescale(coord, details$r.major, details), 0.45)
+ # This gets the proper theme element for theta and r grid lines:
+ # panel.grid.major.x or .y
+ majortheta <- paste("panel.grid.major.", coord$theta, sep = "")
+ minortheta <- paste("panel.grid.minor.", coord$theta, sep = "")
+ majorr <- paste("panel.grid.major.", coord$r, sep = "")
+
ggname("grill", grobTree(
element_render(theme, "panel.background"),
if (length(theta) > 0) element_render(
- theme, "panel.grid.major", name = "angle",
+ theme, majortheta, name = "angle",
x = c(rbind(0, 0.45 * sin(theta))) + 0.5,
y = c(rbind(0, 0.45 * cos(theta))) + 0.5,
id.lengths = rep(2, length(theta)),
default.units="native"
),
if (length(thetamin) > 0) element_render(
- theme, "panel.grid.minor", name = "angle",
+ theme, minortheta, name = "angle",
x = c(rbind(0, 0.45 * sin(thetamin))) + 0.5,
y = c(rbind(0, 0.45 * cos(thetamin))) + 0.5,
id.lengths = rep(2, length(thetamin)),
default.units="native"
),
element_render(
- theme, "panel.grid.major", name = "radius",
+ theme, majorr, name = "radius",
x = rep(rfine, each=length(thetafine)) * sin(thetafine) + 0.5,
y = rep(rfine, each=length(thetafine)) * cos(thetafine) + 0.5,
id.lengths = rep(length(thetafine), length(rfine)),
View
@@ -7,22 +7,22 @@ guide_grid <- function(theme, x.minor, x.major, y.minor, y.major) {
ggname("grill", grobTree(
element_render(theme, "panel.background"),
if(length(y.minor) > 0) element_render(
- theme, "panel.grid.minor", name = "y",
+ theme, "panel.grid.minor.y",
x = rep(0:1, length(y.minor)), y = rep(y.minor, each=2),
id.lengths = rep(2, length(y.minor))
),
if(length(x.minor) > 0) element_render(
- theme, "panel.grid.minor", name = "x",
+ theme, "panel.grid.minor.x",
x = rep(x.minor, each=2), y = rep(0:1, length(x.minor)),
id.lengths = rep(2, length(x.minor))
),
if(length(y.major) > 0) element_render(
- theme, "panel.grid.major", name = "y",
+ theme, "panel.grid.major.y",
x = rep(0:1, length(y.major)), y = rep(y.major, each=2),
id.lengths = rep(2, length(y.major))
),
if(length(x.major) > 0) element_render(
- theme, "panel.grid.major", name = "x",
+ theme, "panel.grid.major.x",
x = rep(x.major, each=2), y = rep(0:1, length(x.major)),
id.lengths = rep(2, length(x.major))
)

0 comments on commit ce9746a

Please sign in to comment.