I'm trying to left justify the axis labels with ggplot2
. Below is the reproducible code. When I try to facet the plot by group, the labels dont align even with hjust=0
option. How do I left align all the Y axis labels?
library(dplyr)
library(reshape2)
library(ggplot2)
dat=read.csv(textConnection(
"Category,Value1,Value2,Total,Group
Geography A,10,10,20,1
Geo B,20,30,50,1
Geo C,5,2,7,1
Geo 2D,5,10,15,2
Geo 2E,10,20,30,2
Geo 2F,30,4,34,2"))
library(tidyverse)
dat %>%
arrange(desc(Group), Total) %>%
mutate(Category = fct_inorder(Category)) %>%
pivot_longer(Value1:Total) -> dat2
ggplot(filter(dat2, name != "Total"),
aes(value, Category, label = value)) +
geom_col(aes(fill = name), position = position_stack(reverse = TRUE)) +
geom_text(position = position_stack(vjust = 0.5, reverse = TRUE)) +
geom_text(data = filter(dat2, name == "Total"),
hjust = -0.5) +theme(axis.text.y.left = element_text(hjust=0.0,size = 14,color = "#001489"))+
facet_grid(rows = vars(Group),scales = 'free_y',space='free_y')