With 'xparams' and 'yparams' parameters can fed to, e.g. the marginal histograms.
However, it appears that 'boundary' is already fixed internally and providing a value is ignored. Likewise, if instead trying to specify only the option 'center' (no 'boundary'), an error is produced that both can't be specified simulatenously.
I've not explored extensively whether other options in x/yparams would also produce errors/be ignored.
Could you please fix this if it's not too much trouble?
Why care?
The default settings in geom_hist are not good (see https://ggplot2.tidyverse.org/reference/geom_histogram.html, Details) and thus flexibility is important- especially for histograms and other graphics where it is known that even small changes in the parameters can have a big effect.
The bars of a histogram for an integer variable (below: x) should be centered on the integer values, i.e. turn into a barplot: e.g., the frequency of x = 1 should be centered on 1 and be above the interval 0.5, 1.5. That is not the case for histogram's default setting. center = 1 or boundary = 0.5 would a quick way to implement this, but these options don't have an effect.
Minimum reproducible example
library(ggplot2)
library(ggExtra)
set.seed(1)
data <- data.frame("y" = runif(n = 100, min = 0, max = 100),
"x" = sample(x = 1:5, size = 100, replace = TRUE,
prob = c(0.1, 0.1, 0.2, 0.2, 0.4)))
p <- ggplot(data, aes(x, y)) +
geom_point() + xlim(0, 6)
# option 'boundary' has no effect, but no message thrown.
(p2 <- ggMarginal(p = p, type = 'histogram',
xparams = list(boundary = 0.5, binwidth = 1)))
(p2 <- ggMarginal(p = p, type = 'histogram',
xparams = list(boundary = 0, binwidth = 1)))
(p2 <- ggMarginal(p = p, type = 'histogram',
xparams = list(boundary = 1.25, binwidth = 1)))
# option 'center' produces an error.
(p2 <- ggMarginal(p = p, type = 'histogram',
xparams = list(center = 1, binwidth = 1)))
# Error: Only one of `boundary` and `center` may be specified.
# ... even though only 'center' was specified, but 'boundary' was not.
# Luckily, option 'breaks' works... if xlim is speficied appropiately
(breaks.seq <- seq(from = min(data$x) - 0.5, by = 1L,
length.out = max(data$x) - min(data$x) + 2))
(p2 <- ggMarginal(p = p, type = 'histogram',
xparams = list(breaks = breaks.seq, binwidth = 1)))
With 'xparams' and 'yparams' parameters can fed to, e.g. the marginal histograms. However, it appears that 'boundary' is already fixed internally and providing a value is ignored. Likewise, if instead trying to specify only the option 'center' (no 'boundary'), an error is produced that both can't be specified simulatenously. I've not explored extensively whether other options in x/yparams would also produce errors/be ignored.
Could you please fix this if it's not too much trouble?
Why care?
Minimum reproducible example