Skip to content

Commit d86acff

Browse files
committed
test: adding Arial Narrow font files
1 parent 0cf2c62 commit d86acff

12 files changed

+25
-21
lines changed

R/clusters.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ clusterKmeans <- function(df, k = NULL, wss_var = 0, limit = 15, drop_na = TRUE,
115115
y = "Within Groups Sum of Squares"
116116
) +
117117
scale_y_comma() +
118-
theme_lares()
118+
theme_lares(...)
119119
results[["nclusters"]] <- nclusters
120120
results[["nclusters_plot"]] <- nclusters_plot
121121

@@ -225,16 +225,16 @@ clusterVisualK <- function(df, ks = 2:6, ...) {
225225
explained <<- clusters$PCA$pca_explained[1:2]
226226
return(pca)
227227
}
228-
clus_plot <- function(clus_dat) {
228+
clus_plot <- function(clus_dat, ...) {
229229
clus_dat %>%
230230
ggplot(aes(x = .data$PC1, y = .data$PC2, colour = as.character(.data$cluster))) +
231231
geom_point() +
232232
guides(colour = "none") +
233233
labs(subtitle = glued("{clus_dat$k[1]} clusters")) +
234-
theme_lares(pal = 2)
234+
theme_lares(pal = 2, ...)
235235
}
236236
dats <- lapply(ks, function(x) clus_dat(df, x, ...))
237-
plots <- lapply(dats, clus_plot)
237+
plots <- lapply(dats, function(x) clus_plot(x, ...))
238238

239239
total <- formatNum(sum(explained), 1, pos = "%")
240240
explained <- formatNum(explained, 1, pos = "%")
@@ -281,7 +281,7 @@ clusterOptimalK <- function(df, method = c("wss", "silhouette", "gap_stat"),
281281
try_require("factoextra")
282282
df <- .prepare_cluster(df, drop_na = drop_na, ohse = ohse, norm = norm, quiet = quiet)
283283
plots <- lapply(method, function(x) {
284-
fviz_nbclust(df, kmeans, method = x, ...) + theme_lares(pal = 2)
284+
fviz_nbclust(df, kmeans, method = x, ...) + theme_lares(pal = 2, ...)
285285
})
286286
return(plots)
287287
}

R/colour_palettes.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ lares_pal <- function(return = "list") {
159159
#' This function plots a list of colours
160160
#'
161161
#' @family Themes
162+
#' @inheritParams cache_write
162163
#' @param fill Vector. List of colours for fills.
163164
#' @param colour Vector. List of colours for colours.
164165
#' @param id Vector. ID for each color.
@@ -173,7 +174,7 @@ lares_pal <- function(return = "list") {
173174
#' pal <- lares_pal("pal")
174175
#' plot_palette(fill = names(pal), colour = as.vector(pal))
175176
#' @export
176-
plot_palette <- function(fill, colour = "black", id = NA, limit = 12) {
177+
plot_palette <- function(fill, colour = "black", id = NA, limit = 12, ...) {
177178
if (length(fill) > limit) {
178179
fill <- fill[1:limit]
179180
colour <- colour[1:limit]
@@ -191,6 +192,6 @@ plot_palette <- function(fill, colour = "black", id = NA, limit = 12) {
191192
coord_flip() +
192193
labs(x = NULL, y = NULL) +
193194
guides(fill = "none", colour = "none") +
194-
theme_lares(font = NA, axis = "Y")
195+
theme_lares(font = NA, axis = "Y", ...)
195196
return(p)
196197
}

R/correlations.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ plot.corr_var <- function(x, var, max_pvalue = 1, top = NA, limit = NULL, ...) {
306306
expand = c(0, 0), position = "right",
307307
labels = function(x) sub("^(-)?0[.]", "\\1.", x)
308308
) +
309-
theme_lares()
309+
theme_lares(...)
310310

311311
if (is.null(limit)) limit <- 100
312312
if (!is.na(top) && top < limit) {
@@ -492,7 +492,7 @@ corr_cross <- function(df, plot = TRUE,
492492
) +
493493
scale_y_continuous(labels = function(x) sub("^(-)?0[.]", "\\1.", x)) +
494494
coord_flip() +
495-
theme_lares(pal = 2)
495+
theme_lares(pal = 2, ...)
496496
}
497497
if (max_pvalue < 1) {
498498
p <- p + labs(caption = paste("Correlations with p-value <", max_pvalue))

R/frequencies.R

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#'
4646
#' # Let's check the results with plots:
4747
#'
48-
#' #' # How many survived and see plot?
48+
#' # How many survived and see plot?
4949
#' dft %>% freqs(Survived, plot = TRUE)
5050
#'
5151
#' # How many survived per class?
@@ -163,13 +163,13 @@ freqs <- function(df, ..., wt = NULL,
163163

164164
# Create some dynamic aesthetics
165165
plot$labels <- paste0(formatNum(plot$n, decimals = 0), " (", signif(plot$p, 4), "%)")
166-
plot$label_colours <- ifelse(plot$p > mean(range(plot$p)) * 0.9, "TRUE", "FALSE")
166+
plot$label_colours <- ifelse(plot$p > mean(range(plot$p)) * 0.9, "white", "black")
167167
lim <- 0.35
168168
plot$label_hjust <- ifelse(
169169
plot$n < min(plot$n) + diff(range(plot$n)) * lim, -0.1, 1.05
170170
)
171171
plot$label_colours <- ifelse(
172-
plot$label_colours == "TRUE" & plot$label_hjust < lim, "FALSE", plot$label_colours
172+
plot$label_colours == "white" & plot$label_hjust < lim, "black", plot$label_colours
173173
)
174174
variable <- colnames(plot)[1]
175175

@@ -220,7 +220,7 @@ freqs <- function(df, ..., wt = NULL,
220220
coord_flip() + guides(colour = "none") +
221221
labs(
222222
x = NULL, y = NULL, fill = NULL,
223-
title = ifelse(is.na(title), paste("Frequencies and Percentages"), title),
223+
title = ifelse(is.na(title), "Frequencies and Percentages", title),
224224
subtitle = ifelse(is.na(subtitle),
225225
paste(
226226
"Variable:", ifelse(!is.na(variable_name), variable_name, variable),
@@ -230,7 +230,8 @@ freqs <- function(df, ..., wt = NULL,
230230
), caption = obs
231231
) +
232232
scale_fill_gradient(low = "lightskyblue2", high = "navy") +
233-
theme_lares(pal = 4, which = "c", legend = "none", grid = "Xx") +
233+
scale_color_identity() +
234+
theme_lares(which = "c", legend = "none", grid = "Xx") +
234235
scale_y_comma(position = "right", expand = c(0, 0), limits = c(0, 1.03 * max(output$n)))
235236

236237
# When two features
@@ -380,7 +381,7 @@ freqs_df <- function(df,
380381
out <- rbind(out, res)
381382
}
382383
out <- out %>%
383-
mutate(p = round(100 * .data$count / nrow(df), 2)) %>%
384+
mutate(p = signif(100 * .data$count / nrow(df), 3)) %>%
384385
mutate(value = ifelse(.data$p > min * 100, as.character(.data$value), "(HF)")) %>%
385386
group_by(.data$col, .data$value) %>%
386387
summarise(p = sum(.data$p), count = sum(.data$count)) %>%
@@ -430,7 +431,7 @@ freqs_df <- function(df,
430431
out <- select(out, .data$col, .data$value, .data$count, .data$p) %>%
431432
rename(n = .data$count, variable = .data$col) %>%
432433
group_by(.data$variable) %>%
433-
mutate(pcum = round(cumsum(.data$p), 2))
434+
mutate(pcum = signif(cumsum(.data$p), 3))
434435
return(out)
435436
}
436437
}

R/theme_lares.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ gg_vals <- function(layer = "fill", column = layer, cols = NULL, ...) {
373373
return(values)
374374
}
375375

376-
.font_global <- function(font, quiet = FALSE, when_not = NA, ask_install = TRUE, ...) {
376+
.font_global <- function(font, quiet = FALSE, when_not = NA, ask_install = FALSE, ...) {
377377
if ("ignore" %in% tolower(font)) {
378378
return(NULL)
379379
} else {
@@ -383,7 +383,7 @@ gg_vals <- function(layer = "fill", column = layer, cols = NULL, ...) {
383383
if (isTRUE(font[1] != "") && !quiet) {
384384
if (ask_install & font[1] %in% list.files(system.file("fonts", package = "lares"))) {
385385
yes <- readline(sprintf("Do you want to install %s font for better results? [y/n]: ", font))
386-
if ("y" %in% yes) install_localfont(font)
386+
if ("y" %in% yes) try(install_localfont(font))
387387
} else {
388388
warning(sprintf("Font(s) %s not installed, with other name, or can't be found", v2t(font)))
389389
}
@@ -400,7 +400,7 @@ gg_vals <- function(layer = "fill", column = layer, cols = NULL, ...) {
400400
}
401401

402402
install_localfont <- function(
403-
font, dir = system.file(paste0("fonts/", font), package = "lares"),
403+
font, dir = system.file(paste0("fonts/", gsub(" ", "_", font)), package = "lares"),
404404
...) {
405405
try_require("extrafont")
406406
font_import(dir, prompt = FALSE, ...)

man/freqs.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_palette.Rd

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)