Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Oct 26, 2016
1 parent 3df3f7e commit 73a65ab
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 56 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export(gtable_squash_cols)
export(gtable_squash_rows)
export(panel_border)
export(plot_grid)
export(plot_theme)
export(save_plot)
export(theme_cowplot)
export(theme_nothing)
Expand Down
6 changes: 3 additions & 3 deletions R/switch_axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ switch_axis_position <- function(plot, axis = c('y', 'x', 'xy'), keep = c('none'
result
}

#' Get theme of a ggplot2 plot
#' @param p The plot
#' @export
# Get theme of a ggplot2 plot
# @param p The plot
# @export
plot_theme <- function(p) {
plyr::defaults(p$theme, ggplot2::theme_get())
}
Expand Down
21 changes: 17 additions & 4 deletions inst/doc/axis_position.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@ require(cowplot)
require(grid) # for unit()
theme_set(theme_cowplot(font_size=12)) # reduce default font size
p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
p1 + theme_gray() + scale_y_continuous(position = "right")
p1 + theme_bw() + scale_x_continuous(sec.axis = dup_axis(name = waiver()))
p1 + scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())
p1 + theme(axis.ticks.length = unit(0.3, "cm"),

# the following code only works for ggplot2 2.2.0 or later
if (packageVersion("ggplot2")>"2.1.0")
p1 + theme_gray() + scale_y_continuous(position = "right")

if (packageVersion("ggplot2")>"2.1.0")
p1 + theme_bw() + scale_x_continuous(sec.axis = dup_axis(name = waiver()))

if (packageVersion("ggplot2")>"2.1.0")
p1 + scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())

if (packageVersion("ggplot2")>"2.1.0")
p1 + theme(axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(margin = margin(0.2, unit = "cm"))) +
scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())

## ---- message=FALSE, fig.width=4.25, fig.height=3------------------------
mtcars2 <- mtcars[1:15, ]
mtcars2$name <- row.names(mtcars2)

# the following code only works for ggplot2 2.2.0 or later
if (packageVersion("ggplot2")>"2.1.0"){
ggplot(mtcars2, aes(x = name, y = mpg, fill = name)) +
geom_bar(stat = 'identity', position = "identity") +
scale_y_reverse() +
guides(fill = FALSE) +
theme(axis.text.x = element_text(angle = 90, vjust=0.5, hjust=0)) +
scale_x_discrete(position = "top")
}

21 changes: 17 additions & 4 deletions inst/doc/axis_position.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ require(cowplot)
require(grid) # for unit()
theme_set(theme_cowplot(font_size=12)) # reduce default font size
p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
p1 + theme_gray() + scale_y_continuous(position = "right")
p1 + theme_bw() + scale_x_continuous(sec.axis = dup_axis(name = waiver()))
p1 + scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())
p1 + theme(axis.ticks.length = unit(0.3, "cm"),
# the following code only works for ggplot2 2.2.0 or later
if (packageVersion("ggplot2")>"2.1.0")
p1 + theme_gray() + scale_y_continuous(position = "right")
if (packageVersion("ggplot2")>"2.1.0")
p1 + theme_bw() + scale_x_continuous(sec.axis = dup_axis(name = waiver()))
if (packageVersion("ggplot2")>"2.1.0")
p1 + scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())
if (packageVersion("ggplot2")>"2.1.0")
p1 + theme(axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(margin = margin(0.2, unit = "cm"))) +
scale_x_continuous(sec.axis = dup_axis()) + scale_y_continuous(sec.axis = dup_axis())
```
Expand All @@ -30,11 +39,15 @@ It is also possible to use alternate discrete axes:
```{r, message=FALSE, fig.width=4.25, fig.height=3}
mtcars2 <- mtcars[1:15, ]
mtcars2$name <- row.names(mtcars2)
# the following code only works for ggplot2 2.2.0 or later
if (packageVersion("ggplot2")>"2.1.0"){
ggplot(mtcars2, aes(x = name, y = mpg, fill = name)) +
geom_bar(stat = 'identity', position = "identity") +
scale_y_reverse() +
guides(fill = FALSE) +
theme(axis.text.x = element_text(angle = 90, vjust=0.5, hjust=0)) +
scale_x_discrete(position = "top")
}
```

20 changes: 15 additions & 5 deletions inst/doc/axis_position.html

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions inst/doc/introduction.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions inst/doc/plot_annotations.html

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion inst/doc/plot_grid.html

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions inst/doc/shared_legends.html

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions man/plot_theme.Rd

This file was deleted.

0 comments on commit 73a65ab

Please sign in to comment.