I'm creating geom_col()
charts in ggplot
faceted across grouping variables. When the groups are charted individually, the charts look like what I expect. But when shown at the same time, a lot of bars (columns) disappear and the rest are shown narrower than before.
By the way, the numbers I'm trying to plot are the outputs from dbplot::db_compute_bins
.So I'm trying to put these columns together to look like a histogram.
Is this behavior by design?
My expected chart is the same chart shown side-by-side, scaled down to fit. How can I get my expected chart?
The data:
test.dataframe = data.frame(
group = rep(c('A', 'B'), each= 5),
bins = c(-9000, -4400, 200, 4800, 9400,
-2360, -1084.8, 190.4, 1465.6, 2740.8),
counts = c(2, 6259, 2950, 8, 6,
22, 609, 543, 62, 5
)
)
First group:
ggplot(test.dataframe %>%
filter(group == 'A')) +
geom_col(aes(x= bins, y= counts)) +
scale_y_log10()
Chart:
Second Group:
ggplot(test.dataframe %>%
filter(group == 'B')) +
geom_col(aes(x= bins, y= counts)) +
scale_y_log10()
Chart:
Now putting them together:
ggplot(test.dataframe) +
geom_col(aes(x= bins, y= counts)) +
scale_y_log10()+
facet_wrap(vars(group),
ncol = 2,
scales = "free")
Chart:
Doing it row-wise results in a different chart, but still not what I expected:
ggplot(test.dataframe) +
geom_col(aes(x= bins, y= counts)) +
scale_y_log10()+
facet_wrap(vars(group),
nrow = 2,
scales = "free")
Result: