This question is in relation to a topic I opened about a month ago (Aligning labels under geom_col with varying widths). The community was great about trying to help me, but I didn't really get where I was trying to go, and more importantly, haven't figured out how to do this right in the future.
I'm trying to learn how to accomplish the following in a geom_col plot:
- Make the column widths proportional to the value of a variable in the dataset;
- Dodge the columns to eliminate overlap due to the new varying widths;
- Make the x-axis labels re-position with the new center of the respective data.
The plot I dropped below has my attempt to add position = "dodge2" to the geom. Without it, the widths seem to track, but the columns stay in place and overlap.
suppressPackageStartupMessages(library(tidyverse)) ggplot(data = mtcars) + geom_col(aes(x = row.names(mtcars), y = mpg, fill = as.factor(cyl)), color = "black", width = mtcars$wt, position = "dodge2") + labs(x = NULL) + theme(axis.text.x = element_text(angle = 90, size = 7, hjust = 1))
Created on 2020-04-07 by the reprex package (v0.3.0)