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
7 changes: 7 additions & 0 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ draw_facet_window = function(grid, ...) {
# extra whitespace bump on the y axis
# yaxl = axTicks(2)
yaxl = axisTicks(usr = extendrange(ylim, f = 0.04), log = par("ylog"))
## overrides for ridge and spineplot types
if (type == "ridge") yaxl = levels(y)
if (type == "spineplot") yaxl = ylabs
# whtsbp = grconvertX(max(strwidth(yaxl, "figure")), from = "nfc", to = "lines") - 1
whtsbp = grconvertX(max(strwidth(yaxl, "figure")), from = "nfc", to = "lines") - grconvertX(0, from = "nfc", to = "lines") - 1
if (whtsbp > 0) {
Expand Down Expand Up @@ -236,10 +239,14 @@ draw_facet_window = function(grid, ...) {
# Dynamic plot margin adjustments
omar = par("mar")
omar = omar - c(0, 0, 1, 0) # reduce top whitespace since no facet (title)
if (type == "spineplot") omar[4] = 2.1 # catch for spineplot RHS axis labs
if (par("las") %in% 1:2) {
# extra whitespace bump on the y axis
# yaxl = axTicks(2)
yaxl = axisTicks(usr = extendrange(ylim, f = 0.04), log = par("ylog"))
## overrides for ridge and spineplot types
if (type == "ridge") yaxl = levels(y)
if (type == "spineplot") yaxl = ylabs
# whtsbp = grconvertX(max(strwidth(yaxl, "figure")), from = "nfc", to = "lines") - 1
whtsbp = grconvertX(max(strwidth(yaxl, "figure")), from = "nfc", to = "lines") - grconvertX(0, from = "nfc", to = "lines") - 1
if (whtsbp > 0) {
Expand Down
1 change: 0 additions & 1 deletion R/tinytheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#' Known current limitations include:
#'
#' - Themes do not work well when `legend = "top!"`.
#' - Themes do not play nicely with some complex plot types, particularly `"spineplot"` and `"ridge"`.
#' - Dynamic margin spacing does not account for multi-line strings (e.g., axes
#' or main titles that contain "\\n").
#'
Expand Down
7 changes: 5 additions & 2 deletions R/type_ridge.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ data_ridge = function(bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512,
dotspal = list(...)[["palette"]]
palette = if (!is.null(dotspal)) dotspal else gradient
gradient = TRUE
if (isTRUE(palette)) palette = "viridis"
if (isTRUE(palette)) {
palette = if (!is.null(.tpar[["palette.sequential"]])) .tpar[["palette.sequential"]] else "viridis"
}

if (length(palette) > 1L || !is.character(palette)) {
## color vector already given
Expand Down Expand Up @@ -380,7 +382,8 @@ draw_ridge = function() {
d = data.frame(x = ix, y = iy, ymin = iymin, ymax = iymax)
dsplit = split(d, d$y)
if (is.null(ibg)) {
ibg = if (isTRUE(type_info[["fill_by"]])) seq_palette(icol, n = 2)[2] else "gray"
default_bg = if (!is.null(.tpar[["palette.qualitative"]])) seq_palette(by_col(), n = 2)[2] else "gray"
ibg = if (isTRUE(type_info[["fill_by"]])) seq_palette(icol, n = 2)[2] else default_bg
}
if (!is.null(type_info[["alpha"]]) && is.null(type_info[["palette"]])) {
ibg = adjustcolor(ibg, alpha.f = type_info[["alpha"]])
Expand Down
3 changes: 2 additions & 1 deletion R/type_spineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ data_spineplot = function(off = NULL, breaks = NULL, ylevels = ylevels, xaxlabel
if (isTRUE(y_by)) datapoints$by = rep(yaxlabels, length.out = nrow(datapoints))

## grayscale flag
grayscale = length(unique(datapoints[["by"]])) == 1 && is.null(palette)
grayscale = length(unique(datapoints[["by"]])) == 1 && is.null(palette) && is.null(.tpar[["palette.qualitative"]])

out = list(
x = c(datapoints$xmin, datapoints$xmax),
Expand All @@ -235,6 +235,7 @@ data_spineplot = function(off = NULL, breaks = NULL, ylevels = ylevels, xaxlabel
yaxt = "n",
xaxs = "i",
yaxs = "i",
ylabs = yaxlabels,
type_info = list(
off = off,
x.categorical = x.categorical,
Expand Down
83 changes: 83 additions & 0 deletions inst/tinytest/_tinysnapshot/tinytheme_dynamic_clean_ridge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions inst/tinytest/_tinysnapshot/tinytheme_dynamic_clean_spineplot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions inst/tinytest/test-tinytheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ tinytheme("dark")
f()
expect_snapshot_plot(f, label = "tinytheme_dynamic_dark_facet")

# ridge and spineplot types (req's extra steps b/c of tinyAxis logic)

tinytheme('clean')

f = function() {
tinyplot(
Species ~ Petal.Length, data = iris, type = "ridge",
main = "Dynamic plot adjustment and whitespace reduction",
sub = "Ridge plot version"
)
}
expect_snapshot_plot(f, label = "tinytheme_dynamic_clean_ridge")

f = function() {
tinyplot(
Species ~ Petal.Length, data = iris, type = "spineplot",
main = "Dynamic plot adjustment and whitespace reduction",
sub = "Spineplot version"
)
}
expect_snapshot_plot(f, label = "tinytheme_dynamic_clean_spineplot")

#
## reset

Expand Down
1 change: 0 additions & 1 deletion man/tinytheme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.