Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local() instead of JS-style IIFE #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# produced vignettes
vignettes/*.html
vignettes/*.pdf
# misc
misc/builds
misc/pre-build
.Rdata
core
inst/doc
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ warnings_are_errors: true
r_packages:
- rmarkdown
- ggplot2
- testthat

r_github_packages:
- jimhester/covr
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Package: ggthemr
Title: Themes for ggplot2
Description: Colour schemes and layouts for ggplot2.
Version: 1.0.1
Version: 1.0.2
Author: Ciaran Tobin
Imports: scales
Imports:
scales
Depends:
R (>= 3.0.0),
ggplot2
License: GPL-3
LazyData: true
Maintainer: 'Ciaran Tobin' <[email protected]>
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

S3method(colour_plot,character)
S3method(colour_plot,ggthemr)
Expand Down
29 changes: 13 additions & 16 deletions R/ggthemr.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#' Set theme for ggplot2
#'
#' Set theme to be applied to all subsequent ggplots.
#'
#' @param palette Colour scheme by name or ggtheme object.
#' @param layout The layout of gridlines, axes etc.
#' @param spacing A numeric value of how much space should exist on any given plot. Low values will result in more cramped plots, higher values will have more whitespace.
#' @param text_size base text size.
#' @param type Set to 'inner' where the background colour should not extend past strictly the plot area (or "panel" in ggplot2 terminology). 'outer' will apply the background colour to the entire plot.
#' @param line_weight The thickness of axes lines and gridlines. Useful for saving plots at different resolutions.
#' @param pos Where the new scales are stored.
#' @param envir The environment where the new scales are stored.
#' @export
#' @author Ciaran Tobin
#' @examples
#' @title Set theme for ggplot2
#' @description Set theme to be applied to all subsequent ggplots.
#' @param palette Colour scheme by name or ggtheme object.
#' @param layout The layout of gridlines, axes etc.
#' @param spacing A numeric value of how much space should exist on any given plot. Low values will result in more cramped plots, higher values will have more whitespace.
#' @param text_size base text size.
#' @param type Set to 'inner' where the background colour should not extend past strictly the plot area (or "panel" in ggplot2 terminology). 'outer' will apply the background colour to the entire plot.
#' @param line_weight The thickness of axes lines and gridlines. Useful for saving plots at different resolutions.
#' @param pos Where the new scales are stored.
#' @param envir The environment where the new scales are stored.
#' @export
#' @author Ciaran Tobin
#' @examples
#' ggthemr('pale', layout = 'scientific', spacing = 2, type = 'inner')

ggthemr <- function(palette = 'dust', layout = 'clear',
spacing = 1.6, text_size = 12, type = 'inner',
line_weight = 0.5, pos = 1, envir = as.environment(pos)) {
Expand Down
6 changes: 3 additions & 3 deletions R/ggthemr_current.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title Store Theme
#' @description Store ggthemr theme.
ggthemr_current <- (function () {
ggthemr_current <- local({
themr <- NULL
list(
get = function () {
Expand All @@ -21,7 +21,7 @@ ggthemr_current <- (function () {
themr <<- NULL
}
)
})()
})


#' @title Get Current Theme
Expand All @@ -39,4 +39,4 @@ is_ggthemr_active <- function ()
ggthemr_current$is_set()

clear_themr <- function ()
ggthemr_current$clear()
ggthemr_current$clear()
10 changes: 10 additions & 0 deletions R/no_axes.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ no_y_axis <- function ()


#' @title Remove ggplot2 x-axis line
#' @description Do not show x-axis line
#' @author Ciaran Tobin
#' @seealso \code{\link{no_y_line}}
#' @export
Expand All @@ -40,6 +41,7 @@ no_x_line <- function ()


#' @title Remove ggplot2 y-axis line
#' @description Do not show y-axis line
#' @author Ciaran Tobin
#' @seealso \code{\link{no_x_line}}
#' @export
Expand All @@ -48,6 +50,7 @@ no_y_line <- function ()


#' @title Remove ggplot2 x-axis text/labels
#' @description Do not show x-axis text/labels
#' @author Ciaran Tobin
#' @seealso \code{\link{no_y_text}}
#' @export
Expand All @@ -56,6 +59,7 @@ no_x_text <- function ()


#' @title Remove ggplot2 y-axis text/labels
#' @description Do not show y-axis text/labels
#' @author Ciaran Tobin
#' @seealso \code{\link{no_x_text}}
#' @export
Expand All @@ -64,6 +68,7 @@ no_y_text <- function ()


#' @title Remove ggplot2 tick marks
#' @description Do not show tick marks for all axes
#' @author Ciaran Tobin
#' @seealso \code{\link{no_x_ticks}}, \code{\link{no_y_ticks}}
#' @export
Expand All @@ -72,6 +77,7 @@ no_ticks <- function ()


#' @title Remove ggplot2 x-axis tick marks
#' @description Do not show tick marks for x-axis
#' @author Ciaran Tobin
#' @seealso \code{\link{no_ticks}}, \code{\link{no_y_ticks}}
#' @export
Expand All @@ -80,6 +86,7 @@ no_x_ticks <- function ()


#' @title Remove ggplot2 y-axis tick marks
#' @description Do not show tick marks for y-axis
#' @author Ciaran Tobin
#' @seealso \code{\link{no_ticks}}, \code{\link{no_x_ticks}}
#' @export
Expand All @@ -88,6 +95,7 @@ no_y_ticks <- function ()


#' @title Remove ggplot2 axes titles
#' @description Do not show titles for all axes
#' @author Ciaran Tobin
#' @seealso \code{\link{no_x_title}}, \code{\link{no_y_title}}
#' @export
Expand All @@ -96,6 +104,7 @@ no_axes_titles <- function ()


#' @title Remove ggplot2 x-axis titles
#' @description Do not show x-axis title
#' @author Ciaran Tobin
#' @seealso \code{\link{no_axes_titles}}, \code{\link{no_y_title}}
#' @export
Expand All @@ -104,6 +113,7 @@ no_x_title <- function ()


#' @title Remove ggplot2 y-axis titles
#' @description Do not show y-axis title
#' @author Ciaran Tobin
#' @seealso \code{\link{no_axes_titles}}, \code{\link{no_x_title}}
#' @export
Expand Down
10 changes: 8 additions & 2 deletions R/no_gridlines.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ no_x_gridlines <- function ()


#' @export
#' @describeIn no_x_gridlines
#' @rdname no_x_gridlines
no_vertical_gridlines <- no_x_gridlines


Expand All @@ -31,35 +31,41 @@ no_y_gridlines <- function ()


#' @export
#' @describeIn no_y_gridlines
#' @rdname no_y_gridlines
no_horizontal_gridlines <- no_y_gridlines

#' @title Remove major gridlines
#' @description Do not show major gridlines
#' @export
no_major_gridlines <- function ()
theme(panel.grid.major = element_blank())

#' @title Remove minor gridlines
#' @description Do not show minor gridlines
#' @export
no_minor_gridlines <- function ()
theme(panel.grid.minor = element_blank())

#' @title Remove major x gridlines
#' @description Do not show major gridlines for x-axis
#' @export
no_major_x_gridlines <- function ()
theme(panel.grid.major.x = element_blank())

#' @title Remove minor x gridlines
#' @description Do not show minor gridlines for x-axis
#' @export
no_minor_x_gridlines <- function ()
theme(panel.grid.minor.x = element_blank())

#' @title Remove major y gridlines
#' @description Do not show major gridlines for y-axis
#' @export
no_major_y_gridlines <- function ()
theme(panel.grid.major.y = element_blank())

#' @title Remove minor y gridlines
#' @description Do not show minor gridlines for y-axis
#' @export
no_minor_y_gridlines <- function ()
theme(panel.grid.minor.y = element_blank())
1 change: 1 addition & 0 deletions R/no_title.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @title Remove ggplot2 title
#' @description Remove the plot title
#' @export
#' @author Ciaran Tobin
no_title <- function ()
Expand Down
33 changes: 21 additions & 12 deletions R/set_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ set_theme <- function (palette, layout, spacing, text_size, type, line_weight) {
margin=margin(),
size = rel(0.8),
colour = text_colour),
strip.text = element_text(
debug=FALSE,
margin=margin(),
size = rel(0.8)),
axis.text.x.top = NULL,
axis.text.y.right = NULL,
axis.line = element_line(
colour = line_colour),
axis.line.x = layout$axis.line.x(colour = line_colour),
Expand All @@ -63,20 +61,25 @@ set_theme <- function (palette, layout, spacing, text_size, type, line_weight) {
axis.title.x = element_text(
debug=FALSE,
margin=margin(),
vjust=x_title_spacing(spacing)),
vjust=x_title_spacing(spacing)),
axis.title.x.top = NULL,
axis.title.y = element_text(
debug=FALSE,
margin=margin(),
angle = 90,
vjust=y_title_spacing(spacing)),
axis.title.y.right = NULL,
axis.ticks.length = grid::unit(0.15, "cm"),
legend.background = element_rect(
colour = ifelse(inner, 'white', palette$background),
fill = ifelse(inner, 'white', palette$background)),
legend.margin = grid::unit(0.2 * spacing, "cm"),
legend.margin = NULL,
legend.spacing = grid::unit(0.2 * spacing, "cm"),
legend.key = element_rect(
colour = ifelse(inner, 'white', palette$background),
fill = palette$background),
legend.spacing.x = NULL,
legend.spacing.y = NULL,
legend.key.size = grid::unit(
1.2, "lines"),
legend.key.height = NULL,
Expand All @@ -97,15 +100,18 @@ set_theme <- function (palette, layout, spacing, text_size, type, line_weight) {
legend.direction = NULL,
legend.justification = "center",
legend.box = NULL,
legend.box.margin = NULL,
legend.box.background = NULL,
legend.box.spacing = NULL,
panel.background = element_rect(
fill = palette$background,
colour = NA),
panel.border = element_blank(),
panel.grid.major = layout$panel.grid.major(colour = palette$gridline),
panel.grid.minor = layout$panel.grid.minor(colour = palette$gridline),
panel.margin = grid::unit(0.5 * spacing, 'cm'),
panel.margin.x = NULL,
panel.margin.y = NULL,
panel.spacing = grid::unit(0.5 * spacing, 'cm'),
panel.spacing.x = NULL,
panel.spacing.y = NULL,
panel.ontop = FALSE,
strip.background = element_rect(
fill = ifelse(inner, 'white', palette$background),
Expand All @@ -124,15 +130,18 @@ set_theme <- function (palette, layout, spacing, text_size, type, line_weight) {
size = rel(1.1)),
strip.switch.pad.grid = grid::unit(0, 'cm'),
strip.switch.pad.wrap = grid::unit(0, 'cm'),
strip.placement = NULL,
plot.background = element_rect(
colour = ifelse(inner, 'white', palette$background),
fill = ifelse(inner, 'white', palette$background)),
plot.title = element_text(
debug=FALSE,
margin=margin(),
size = rel(1.2),
vjust = spacing + 0.2,
margin=margin(0, 0, 6.6, 0),
size = rel(1.2),
vjust = spacing,
face='bold'),
plot.subtitle = NULL,
plot.caption = NULL,
plot.margin = grid::unit(c(0.625, 0.625, 0.625, 0.625) * spacing, 'cm'),
complete = TRUE
))
Expand Down
Loading