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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ where the formatting is also better._
x-axis order of the original plot layer. This should ensure that we don't end
up with misaligned layers. For example, when ribbon is added on top of an
errorbar plot. (#517, #520, #523, #526 @grantmcdermott)
- Custom axis titles work properly for one-sided (formula) bar plots. Thanks to
@lbelzile for the report in #423. (#527 @grantmcdermott)


### Documentation
Expand Down
18 changes: 12 additions & 6 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1463,17 +1463,23 @@ tinyplot.formula = function(
}

## nice axis and legend labels
dens_type = (is.atomic(type) && identical(type, "density")) || (!is.atomic(type) && identical(type$name, "density"))
hist_type = (is.atomic(type) && type %in% c("hist", "histogram")) || (!is.atomic(type) && identical(type$name, "histogram"))
if (!is.null(type) && dens_type) {
dens_type = !is.null(type) && (is.atomic(type) && identical(type, "density")) || (!is.atomic(type) && identical(type$name, "density"))
hist_type = !is.null(type) && (is.atomic(type) && type %in% c("hist", "histogram")) || (!is.atomic(type) && identical(type$name, "histogram"))
barp_type = !is.null(type) && (is.atomic(type) && identical(type, "barplot")) || (!is.atomic(type) && identical(type$name, "barplot"))
if (dens_type) {
# if (is.null(ylab)) ylab = "Density" ## rather assign ylab as part of internal type_density() logic
if (is.null(xlab)) xlab = xnam
} else if (!is.null(type) && hist_type) {
} else if (hist_type) {
# if (is.null(ylab)) ylab = "Frequency" ## rather assign ylab as part of internal type_histogram() logic
if (is.null(xlab)) xlab = xnam
} else if (is.null(y)) {
if (is.null(ylab)) ylab = xnam
if (is.null(xlab)) xlab = "Index"
if (!barp_type) {
if (is.null(ylab)) ylab = xnam
if (is.null(xlab)) xlab = "Index"
} else {
if (is.null(ylab)) ylab = "Count"
if (is.null(xlab)) xlab = xnam
}
} else {
if (is.null(ylab)) ylab = ynam
if (is.null(xlab)) xlab = xnam
Expand Down
5 changes: 2 additions & 3 deletions R/type_barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,

## tabulate/aggregate datapoints
if (is.null(datapoints$y)) {
xlab = ylab
ylab = "Count"

if (is.null(xlab) || xlab == "Index") xlab = ylab
if (is.null(settings$y_dep) && is.null(ylab)) ylab = "Count"
datapoints$y = numeric(nrow(datapoints))
if (!is.null(FUN)) warning("without 'y' variable 'FUN' specification is ignored")
FUN = length
Expand Down
101 changes: 101 additions & 0 deletions inst/tinytest/_tinysnapshot/barplot_custom_xtitle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions inst/tinytest/_tinysnapshot/barplot_custom_ytitle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading