cols.df <- data.frame(x1 = c(1, 2, 1, 3),
x2 = c("a", "a", "b", "b"),
grp = c("A", "B", "C", "D"))
ggplot(data = cols.df, aes(x2, x1, group = grp)) +
geom_col(aes(fill = grp), width=0.5, position = "stack") +
geom_vline(xintercept = 0) +
geom_text_s(
aes(label = x1),
position = position_stacknudge_to(x = c(1.4, 1.4, 1.6, 1.6))) +
theme(legend.position = "none")
ggplot(data = cols.df, aes(x2, x1, group = grp)) +
geom_col(aes(fill = grp), width=0.5, position = "fill") +
geom_vline(xintercept = 0) +
geom_text_s(
aes(label = grp),
position = position_fillnudge_to(x = c(1.4, 1.4, 1.6, 1.6))) +
theme(legend.position = "none")
ggplot(data = cols.df, aes(x2, x1, group = grp)) +
geom_col(aes(fill = grp), width=0.5, position = "fill") +
geom_vline(xintercept = 0) +
geom_text_s(
aes(label = x1),
position = position_fillnudge_to(vjust = 0.5,
x = c(1.4, 1.4, 1.6, 1.6))) +
theme(legend.position = "none")
ggplot(data = cols.df, aes(x2, x1, group = grp)) +
geom_col(aes(fill = grp), width=0.5, position = "fill") +
geom_vline(xintercept = 0) +
geom_text_s(
aes(label = x1), vjust = 0.5,
position = position_fillnudge_to(vjust = 0.5,
x = c(1.4, 1.4, 1.6, 1.6),
y = c(0.85, 0.35, 0.85, 0.35))) +
theme(legend.position = "none")
Run the code above in your browser using DataLab