0

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?

enter image description here

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')
forecaster
  • 1,084
  • 1
  • 14
  • 35
  • 1
    Seems there is no easy fix. See [Alignment of y axis labels in faced_grid and ggplot?](https://stackoverflow.com/questions/55080119/alignment-of-y-axis-labels-in-faced-grid-and-ggplot) or [ggplot2: yaxis labels not aligning across facets](https://stackoverflow.com/questions/48533942/ggplot2-yaxis-labels-not-aligning-across-facets) and [Left-adjust (hjust = 0) vertical x axis labels on facets with free scale](https://stackoverflow.com/questions/60682885/left-adjust-hjust-0-vertical-x-axis-labels-on-facets-with-free-scale) for some options. – stefan Aug 30 '23 at 21:17

0 Answers0