Skip to content

Commit

Permalink
update 2.0.0
Browse files Browse the repository at this point in the history
Merge branch 'dev'

# Conflicts:
#	R/insert_worksheet.R
#	R/quickXLSX.R
#	R/splitXLSX.R
#	README.md
  • Loading branch information
Michelle Donzallaz committed Jun 4, 2021
2 parents d84ff14 + 2e04490 commit 0a3e717
Show file tree
Hide file tree
Showing 177 changed files with 13,273 additions and 773 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^pkgdown$
^docs$
^man-roxygen$
^index\.html$
26 changes: 19 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
Package: statR
Title: statR
Version: 0.0.0.9000
Version: 2.0.0
Authors@R: as.person(c(
"Andrea Schnell <[email protected]> [aut]",
"Thomas Lo Russo <[email protected]> [aut,cre]"))
Description: statR bundles a variety of functions that allow to generate ready-to-publish plots (ggplot2-theme & colorpalettes) as well as saving data in formated excel-tables. The generated outputs are aligned with the corporate design of the Canton Zurich.
"Thomas Lo Russo <[email protected]> [aut,cre]",
"Michelle Donzallaz <[email protected]> [ctb]"))
Description: statR beinhaltet eine Reihe von Funktionen mit denen unter anderem publikationsfertige Visualisierungen (mittels ggplot2-themes und Farbpaletten) und formatierte Excel-Tabellen erstellt werden können. Die generierten Visualisierungen und Tabellen sind an das Corporate Design des Kantons Zürich angepasst.
Depends: R (>= 3.3.0)
License: What license is it under?
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
RoxygenNote: 7.1.1
Imports:
dplyr,
ggrepel,
ggplot2,
openxlsx,
magrittr
openxlsx,
magrittr,
stats,
grDevices,
RColorBrewer,
gridExtra,
rlang,
scales,
stringr,
tidyr,
dichromat,
purrr
URL: https://statistikzh.github.io/statR/
BugReports: https://github.com/statistikZH/statR/issues
Suggests:
Expand Down
595 changes: 595 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# Generated by roxygen2: do not edit by hand

export(datasetsXLSX)
export(display)
export(display.statcol.all)
export(insert_worksheet)
export(interpolate2)
export(quickXLSX)
export(quick_sum)
export(splitXLSX)
export(stattheme_data)
export(theme_stat)
export(zhpal)
importFrom(dplyr,"%>%")
importFrom(dplyr,group_by)
importFrom(dplyr,n)
importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(ggplot2,continuous_scale)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
importFrom(ggplot2,ggplotGrob)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(ggplot2,unit)
importFrom(grDevices,"colorRampPalette")
importFrom(graphics,"rect")
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(stats,sd)
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# statR 2.0.0

* An R Markdown template `ZH report` for .html-reports is now available.
* New function `datasetsXLSX()`: several datasets and/or figures can now be exported from R to a single .xlsx-file. The function creates an overview sheet and separate sheets for each dataset/figure.
* Additional function arguments for `quickXLSX()`, `splitXLSX()`, and `datasetsXLSX()` have been implemented, for example the author's initials and individual contact details can be specified and the logo of the canton of Zurich can be added.
* The column widths in the output of `quickXLSX()`, `splitXLSX()`, and `datasetsXLSX()` are set automatically and the first row no longer freezes.
* The documentation has been extended.
* `theme_stat()` has been revised and a couple of theme arguments have been added for increased flexibility (e.g., axis ticks, position of axis labels)
213 changes: 3 additions & 210 deletions R/col_stat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library(scales)
#' Data used by the stat zh palettes
#'
#' @format A \code{list}.
#' @export
#' @noRd
#'
stattheme_data <- {

Expand Down Expand Up @@ -197,193 +197,19 @@ stattheme_data <- {
#'
#' Stat ZH scales
#' @keywords stattheme_pal
#' @examples
#' stattheme_pal()
#' @noRd
#'

#Funktion für Palettenauswahl (ord./kat.)

stattheme_pal <- function(palette = "default") {
if (palette %in% names(x$stattheme_data)) {
manual_pal(unname( x$stattheme_data[[palette]]))
scales::manual_pal(unname( x$stattheme_data[[palette]]))
} else {
stop(sprintf("palette %s not a valid statZH palette.", palette))
}
}

# scale_fill_stat()

#' scale_fill_stat()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_fill_stat
#' @examples
#' scale_fill_stat()
#'
# Funktion für Palettenauswahl (ord./kat.)

scale_fill_stat <- function(palette = "zh",...) {

discrete_scale("fill", "stat", stattheme_pal(palette), ...)

}

# scale_colour_stat()

#' scale_colour_stat()
#'
#' Stat ZH scales
#' @keywords scale_colour_stat
#' @examples
#' scale_colour_stat()
#'
# Funktion für Palettenauswahl (ord./kat.)

scale_color_stat <- scale_colour_stat <- function(palette = "zh",...) {

discrete_scale("colour", "stat", stattheme_pal(palette), ...)

}

#' scale_seq_gradient()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_seq_gradient
#' @examples
#' scale_seq_gradient()
#'
# Funktion für sequentielle Paletten

stat_seq_gradient_pal <- function(palette = "zhblue", space = "Lab") {
if (palette %in% names(x$stattheme_data[["sequential"]])) {
manual_pal(unname(x$stattheme_data[["sequential"]][[palette]]))
} else {
stop(sprintf("palette %s not a valid statZH palette.", palette))
}
pal <- x$stattheme_data[["sequential"]][[palette]]
seq_gradient_pal(low = pal["low"], high = pal["high"]
)
}

#' scale_color_gradient_stat()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_color_gradient_stat
#' @examples
#' scale_color_gradient_stat()
#'
# Funktion für sequentielle Paletten

scale_color_gradient_stat<- scale_colour_gradient_stat <- function(palette = "zhblueseq",
...,
space = "Lab",
na.value = "grey50",
guide = "colourbar") {
continuous_scale("colour", "stat",
stat_seq_gradient_pal(palette, space),
na.value = na.value,
guide = guide,
...)
}

#' scale_fill_gradient_stat()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_fill_gradient_stat
#' @examples
#' scale_fill_gradient_stat()
#'
# Funktion für sequentielle Paletten

scale_fill_gradient_stat<- function(palette = "zhblueseq",
..., space = "Lab",
na.value = "grey50",
guide = "colourbar") {
continuous_scale("fill", "stat",
stat_seq_gradient_pal(palette, space),
na.value = na.value,
guide = guide,
...)
}

#' mid_rescaler()
#'
#' Stat ZH scales
#' @param
#' @keywords mid_rescaler
#' @examples
#' mid_rescaler()
#'
# Function to define midpoint (diverging scales)

mid_rescaler <- function(mid) {
function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) {
rescale_mid(x, to, from, mid)
}
}

#' stat_div_gradient_pal()
#'
#' Stat ZH scales
#' @param
#' @keywords stat_div_gradient_pal
#' @examples
#' stat_div_gradient_pal()
#'
# Function to define midpoint (diverging scales)

stat_div_gradient_pal <- function(palette = "zhbluered", space = "Lab") {
if (palette %in% names(x$stattheme_data[["diverging"]])) {
manual_pal(unname(x$stattheme_data[["diverging"]][[palette]]))
} else {
stop(sprintf("palette %s not a valid statZH palette.", palette))
}

pal <- x$stattheme_data[["diverging"]][[palette]]
div_gradient_pal(low = pal["low"], mid = pal["mid"], high = pal["high"],
space = space)
}

#' scale_color_gradient2_stat()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_color_gradient2_stat
#' @examples
#' scale_color_gradient2_stat()
#'
# Function for diverging scales

scale_color_gradient2_stat <- scale_colour_gradient2_stat <- function(palette = "zhbluered",
..., space = "Lab",
na.value = "grey50",
guide = "colourbar",
midpoint=0) {
continuous_scale("colour", "stat2",
stat_div_gradient_pal(palette, space),
na.value = na.value,
guide = guide,
rescaler = mid_rescaler(mid = midpoint),
...)
}


scale_fill_gradient2_stat <- function(palette = "zhbluered",
..., space = "Lab",
na.value = "grey50",
guide = "colourbar", midpoint=0) {
continuous_scale("fill", "stat2",
stat_div_gradient_pal(palette, space),
na.value = na.value,
guide = guide,
rescaler = mid_rescaler(mid = midpoint),
...)
}


#' Data used by the stat zh palettes
#'
Expand All @@ -392,36 +218,3 @@ scale_fill_gradient2_stat <- function(palette = "zhbluered",
#'

zhpal <- x$stattheme_data


#' scale_color_gradientn_stat()
#'
#' Stat ZH scales
#' @param
#' @keywords scale_color_gradientn_stat
#' @examples
#' scale_color_gradientn_stat()
#'
# Function for customized scales with multiple hues


scale_color_gradientn_stat <- scale_colour_gradientn_stat <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", colors) {

if(missing(colours)) colours <- c("#FFE16F","#56BFB9","#003B5E")

colours <- if (missing(colours)) colors else colours

continuous_scale("colour", "gradientn",
gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...)
}


scale_fill_gradientn_stat <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", colors) {

if(missing(colours)) colours <- c("#FFE16F","#56BFB9","#003B5E")

colours <- if (missing(colours)) colors else colours

continuous_scale("fill", "gradientn",
gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...)
}
Loading

0 comments on commit 0a3e717

Please sign in to comment.