Skip to content

Commit

Permalink
Theme axis border, and fix theme_segment bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jul 7, 2008
1 parent ee559e1 commit de9b599
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 8 additions & 1 deletion R/guides-axis.r
Expand Up @@ -39,6 +39,13 @@ guide_axis <- function(at, labels, position="right", theme) {
}
labels <- theme_render(theme, label_render, labels, label_x, label_y)

line <- switch(position,
top = theme_render(theme, "axis.line", 0, 0, 1, 0),
bottom = theme_render(theme, "axis.line", 0, 1, 1, 1),
right = theme_render(theme, "axis.line", 0, 1, 0, 1),
left = theme_render(theme, "axis.line", 1, 0, 1, 1)
)

ticks <- switch(position,
top = theme_render(theme, "axis.ticks.x", at, 0, at, length),
bottom = theme_render(theme, "axis.ticks.x", at, one - length, at, 1),
Expand All @@ -47,7 +54,7 @@ guide_axis <- function(at, labels, position="right", theme) {
)

absoluteGrob(
grobTree(ticks, labels),
grobTree(ticks, labels, line),
width = grobWidth(labels) + label_pos,
height = grobHeight(labels) + label_pos
)
Expand Down
3 changes: 1 addition & 2 deletions R/theme-defaults.r
Expand Up @@ -5,8 +5,7 @@
# foreground colour (and interpolate between them? prob won't work)
theme_gray <- function(base_size = 12) {
structure(list(
# axis.box = theme_blank(),
axis.line = theme_line(),
axis.line = theme_blank(),
axis.text.x = theme_text(size = base_size / 1.2 , lineheight = 0.9, colour = "grey50", vjust = 1),
axis.text.y = theme_text(size = base_size / 1.2, lineheight = 0.9, colour = "grey50", hjust = 1),
axis.ticks.x = theme_segment(colour = "grey50"),
Expand Down
2 changes: 1 addition & 1 deletion R/theme-elements.r
Expand Up @@ -49,7 +49,7 @@ theme_segment <- function(colour = "black", size = 0.5, linetype = 1) {
function(x0 = 0, y0 = 0, x1 = 1, y1 = 1, ...) {
segmentsGrob(
x0, y0, x1, y1, ..., default.units = "npc",
gp=gpar(size=unit(size, "mm"), col=colour, lty=linetype),
gp=gpar(col=colour, lty=linetype, lwd = size),
)
},
class = "theme",
Expand Down

0 comments on commit de9b599

Please sign in to comment.