Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@

^data-raw$
^CITATION\.cff$
^CLAUDE\.md$
^\.claude$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata

/.quarto/
CLAUDE.md
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Suggests:
clipr,
svglite
Depends:
R (>= 3.2.0)
R (>= 3.3.0)
Imports:
ggplot2 (>= 2.2.1),
ggplot2 (>= 3.5.0),
grDevices,
grid,
scales,
extrafont,
systemfonts,
knitr,
rmarkdown,
htmltools,
Expand All @@ -40,9 +40,7 @@ Imports:
dplyr,
stringr,
farver,
hunspell,
Rttf2pt1,
extrafont
hunspell
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
VignetteBuilder: knitr
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export(theme_kth_osc)
export(unpaywall_colors)
export(update_geom_font_defaults)
export(use_quarto_ext)
import(extrafont)
import(ggplot2)
import(grDevices)
import(grid)
Expand Down Expand Up @@ -80,6 +79,7 @@ importFrom(scales,show_col)
importFrom(stats,setNames)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(systemfonts,system_fonts)
importFrom(tidyr,pivot_longer)
importFrom(tools,file_path_sans_ext)
importFrom(utils,file.edit)
10 changes: 1 addition & 9 deletions R/font-figtree.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#' Import Figtree font for use in charts
#'
#' There is an option `ktheme.loadfonts` which -- if set to `TRUE` -- will
#' call `extrafont::loadfonts()` to register non-core fonts with R PDF & PostScript
#' devices. If you are running under Windows, the package calls the same function
#' to register non-core fonts with the Windows graphics device.
#'
#' @md
#' @note This will take care of ensuring PDF/PostScript usage. The location of the
#' font directory is displayed after the base import is complete. It is highly
#' @note The location of the font directory is displayed. It is highly
#' recommended that you install them on your system the same way you would any
#' other font you wish to use in other programs.
#' @export
import_figtree <- function() {

os_font_dir <- system.file("fonts", "figtree", package="ktheme")

suppressWarnings(suppressMessages(extrafont::font_import(os_font_dir, prompt=FALSE)))

message(
sprintf(
"You will likely need to install these fonts on your system as well.\n\nYou can find them in [%s]",
Expand Down
10 changes: 1 addition & 9 deletions R/font-georgia.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#' Import Open Sans font for use in charts
#'
#' There is an option `ktheme.loadfonts` which -- if set to `TRUE` -- will
#' call `extrafont::loadfonts()` to register non-core fonts with R PDF & PostScript
#' devices. If you are running under Windows, the package calls the same function
#' to register non-core fonts with the Windows graphics device.
#'
#' @md
#' @note This will take care of ensuring PDF/PostScript usage. The location of the
#' font directory is displayed after the base import is complete. It is highly
#' @note The location of the font directory is displayed. It is highly
#' recommended that you install them on your system the same way you would any
#' other font you wish to use in other programs.
#' @export
import_georgia <- function() {

georgia_font_dir <- system.file("fonts", "georgia", package="ktheme")

suppressWarnings(suppressMessages(extrafont::font_import(georgia_font_dir, prompt=FALSE)))

message(
sprintf(
"You will likely need to install these fonts on your system as well.\n\nYou can find them in [%s]",
Expand Down
10 changes: 1 addition & 9 deletions R/font-open-sans-condensed.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#' Import Open Sans font for use in charts
#'
#' There is an option `ktheme.loadfonts` which -- if set to `TRUE` -- will
#' call `extrafont::loadfonts()` to register non-core fonts with R PDF & PostScript
#' devices. If you are running under Windows, the package calls the same function
#' to register non-core fonts with the Windows graphics device.
#'
#' @md
#' @note This will take care of ensuring PDF/PostScript usage. The location of the
#' font directory is displayed after the base import is complete. It is highly
#' @note The location of the font directory is displayed. It is highly
#' recommended that you install them on your system the same way you would any
#' other font you wish to use in other programs.
#' @export
import_open_sans_condensed <- function() {

os_font_dir <- system.file("fonts", "open-sans-condensed", package="ktheme")

suppressWarnings(suppressMessages(extrafont::font_import(os_font_dir, prompt=FALSE)))

message(
sprintf(
"You will likely need to install these fonts on your system as well.\n\nYou can find them in [%s]",
Expand Down
10 changes: 1 addition & 9 deletions R/font-open-sans.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#' Import Open Sans font for use in charts
#'
#' There is an option `ktheme.loadfonts` which -- if set to `TRUE` -- will
#' call `extrafont::loadfonts()` to register non-core fonts with R PDF & PostScript
#' devices. If you are running under Windows, the package calls the same function
#' to register non-core fonts with the Windows graphics device.
#'
#' @md
#' @note This will take care of ensuring PDF/PostScript usage. The location of the
#' font directory is displayed after the base import is complete. It is highly
#' @note The location of the font directory is displayed. It is highly
#' recommended that you install them on your system the same way you would any
#' other font you wish to use in other programs.
#' @export
import_open_sans <- function() {

os_font_dir <- system.file("fonts", "open-sans", package="ktheme")

suppressWarnings(suppressMessages(extrafont::font_import(os_font_dir, prompt=FALSE)))

message(
sprintf(
"You will likely need to install these fonts on your system as well.\n\nYou can find them in [%s]",
Expand Down
8 changes: 2 additions & 6 deletions R/ktheme-package.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#' Theme and Theme Components for ggplot2 for KTH's graphical profile
#'
#' The core themes: `theme_kth_neo` uses Figtree and `theme_kth` uses Open Sans.
#' There is an option `ktheme.loadfonts` which – if set to `TRUE` – will
#' call `extrafont::loadfonts()` to register non‑core fonts with R PDF &
#' PostScript devices. On Windows the same function registers the fonts
#' with the Windows graphics device.
#'
#' @keywords internal
#' @import ggplot2 grid scales extrafont grDevices
#' @import ggplot2 grid scales grDevices
#' @importFrom systemfonts system_fonts
#' @importFrom magrittr %>%
#' @importFrom gdtools set_dummy_conf
#' @import rmarkdown knitr htmltools
Expand Down
22 changes: 11 additions & 11 deletions R/palette.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ hexes_neo <- function() {
list(
#här överst "primärfärger"
blue = "#004791", ## KTH-blå
sand = "#EBE5E0", # Sand
sand = "#e6e1dd", # Sand
cyan = "#6298D2", # Himmelsblå
darkblue = "#000061", # Marinblå
lightblue = "#DEF0FF", # Ljusblå
digitalblue = "#0029ED", # Digitalblå (undvik)
darkblue = "#08004f", # Marinblå
lightblue = "#e0edfc", # Ljusblå
digitalblue = "#221dd9", # Digitalblå (undvik)
# här under "funktionsfärger"
darkred = "#78001A", # Mörk tegel
red = "#E86A58", # Tegel
darkred = "#bf2c17", # Mörk tegel
red = "#d8351e", # Tegel
pink = "#FFCCC4", # Ljus tegel
darkyellow = "#A65900", # Mörkgul
yellow = "#FFBE00", # Gul
lightyellow = "#FFF0B0", # Ljusgul
darkgreen = "#0D4A21", # Mörkgrön
green = "#4DA060", # Grön
lightgreen = "#C7EBBA", # Ljusgrön
lightyellow = "#FFF080", # Ljusgul
darkgreen = "#366f43", # Mörkgrön
green = "#3f824e", # Grön
lightgreen = "#d8ffe7", # Ljusgrön
darkteal = "#1C434C", # Mörkturkos
teal = "#339C9C", # Turkos
lightteal = "#B2E0E0", # Ljusturkos
Expand Down Expand Up @@ -151,7 +151,7 @@ palette_kth_neo <- function(n = 12, name = "KTH", type = c("qual", "seq", "div")
qual <- c(
hexes$blue, hexes$yellow, hexes$green, hexes$red, hexes$teal, hexes$gray,
hexes$lightblue, hexes$lightyellow, hexes$lightgreen, hexes$pink, hexes$lightteal, hexes$sand,
hexes$darkblue, hexes$darkyellow, hexes$darkgreen, hexes$purple, hexes$darkteal, hexes$darkgray
hexes$darkblue, hexes$darkyellow, hexes$darkgreen, hexes$darkred, hexes$darkteal, hexes$darkgray
)
qual <- setNames(qual, c(
"blue", "yellow", "green", "red", "teal", "gray",
Expand Down
38 changes: 22 additions & 16 deletions R/scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ is.formula <- function (x) { inherits(x, "formula") }
#' @param position The position of the axis. "left" or "right" for vertical
#' scales, "top" or "bottom" for horizontal scales
#' @param sec.axis specify a secondary axis
#' @param n.breaks number of breaks (passed to [ggplot2::continuous_scale()])
#' @param guide axis guide; default `waiver()` uses ggplot2's standard guide
#' @export
scale_x_percent <- function(name = waiver(), breaks = waiver(),
minor_breaks = waiver(),
minor_breaks = waiver(), n.breaks = NULL,
limits = NULL, expand = c(0.01,0), oob = censor,
na.value = NA_real_, trans = "identity",
position = "bottom", sec.axis = waiver(), labels,
guide = waiver(),
accuracy = 1, scale = 100, prefix = "", suffix = "%",
big.mark = " ", decimal.mark = ".", trim = TRUE, ...) {

Expand All @@ -71,18 +74,18 @@ scale_x_percent <- function(name = waiver(), breaks = waiver(),
"x", "xmin", "xmax", "xend", "xintercept", "xmin_final",
"xmax_final", "xlower", "xmiddle", "xupper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
minor_breaks = minor_breaks,
n.breaks = n.breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = "none",
transform = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
Expand All @@ -103,10 +106,11 @@ scale_x_percent <- function(name = waiver(), breaks = waiver(),
#' @rdname scale_x_percent
#' @export
scale_y_percent <- function(name = waiver(), breaks = waiver(),
minor_breaks = waiver(),
minor_breaks = waiver(), n.breaks = NULL,
limits = NULL, expand = c(0.01,0), oob = censor,
na.value = NA_real_, trans = "identity",
position = "left", sec.axis = waiver(), labels,
guide = waiver(),
accuracy = 1, scale = 100, prefix = "", suffix = "%",
big.mark = " ", decimal.mark = ".", trim = TRUE, ...) {

Expand All @@ -128,18 +132,18 @@ scale_y_percent <- function(name = waiver(), breaks = waiver(),
"y", "ymin", "ymax", "yend", "yintercept",
"ymin_final", "ymax_final", "lower", "middle", "upper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
minor_breaks = minor_breaks,
n.breaks = n.breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = "none",
transform = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
Expand All @@ -163,11 +167,12 @@ scale_y_percent <- function(name = waiver(), breaks = waiver(),
#' @param ... passed on to [scales::comma_format()] or [scales::percent_format()]
#' @export
scale_x_comma <- function(name = waiver(), breaks = waiver(),
minor_breaks = waiver(),
minor_breaks = waiver(), n.breaks = NULL,
limits = NULL,
expand = c(0.01,0), oob = censor,
na.value = NA_real_, trans = "identity",
position = "bottom", sec.axis = waiver(), labels,
guide = waiver(),
accuracy = 1, scale = 1, prefix = "", suffix = "",
big.mark = ",", decimal.mark = ".", trim = TRUE,
...) {
Expand All @@ -191,18 +196,18 @@ scale_x_comma <- function(name = waiver(), breaks = waiver(),
"xmin_final", "xmax_final",
"xlower", "xmiddle", "xupper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
minor_breaks = minor_breaks,
n.breaks = n.breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = "none",
transform = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
Expand All @@ -224,10 +229,11 @@ scale_x_comma <- function(name = waiver(), breaks = waiver(),
#' @export
scale_y_comma <- function(name = waiver(),
breaks = waiver(),
minor_breaks = waiver(),
minor_breaks = waiver(), n.breaks = NULL,
limits = NULL, expand = c(0.01,0), oob = censor,
na.value = NA_real_, trans = "identity",
position = "left", sec.axis = waiver(), labels,
guide = waiver(),
accuracy = 1, scale = 1, prefix = "", suffix = "",
big.mark = ",", decimal.mark = ".", trim = TRUE,
...) {
Expand All @@ -251,18 +257,18 @@ scale_y_comma <- function(name = waiver(),
"ymin_final", "ymax_final",
"lower", "middle", "upper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
minor_breaks = minor_breaks,
n.breaks = n.breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = "none",
transform = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
Expand Down
15 changes: 2 additions & 13 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
.onAttach <- function(libname, pkgname) {

if (.Platform$OS.type == "windows") { # nocov start
if (interactive()) packageStartupMessage("Registering Windows fonts with R")
extrafont::loadfonts("win", quiet = TRUE)
}

if (getOption("ktheme.loadfonts", default = FALSE)) {
if (interactive()) packageStartupMessage("Registering PDF & PostScript fonts with R")
extrafont::loadfonts("pdf", quiet = TRUE)
extrafont::loadfonts("postscript", quiet = TRUE)
}

fnt <- extrafont::fonttable()
if (!any(grepl("Open[ ]Sans|Georgia|Figtree", fnt$FamilyName))) {
fnt <- systemfonts::system_fonts()
if (!any(grepl("Open[ ]Sans|Georgia|Figtree", fnt$family))) {
packageStartupMessage("NOTE: Either Open Sans or Georgia fonts or Figtree are required to use these themes.")
packageStartupMessage(" Please use ktheme::import_open_sans() to install Open Sans and")
packageStartupMessage(" please use ktheme::import_figtree() to install Figtree and")
Expand Down
Loading
Loading