Home > other >  In ggplot2 , how to align label x text in vertical
In ggplot2 , how to align label x text in vertical

Time:05-09

In ggplot2 , how to align label x in vertical ? The wished result as attached image .

library(tidyverse)
category <- c("A B C","DF GC","S AA")
amount <- c(3,2,1)

plot_data <- data.frame(category,amount)

plot_data %>% ggplot(aes(x=category,y=amount)) geom_col()

enter image description here

CodePudding user response:

Try this:

library(tidyverse)
category <- c("A B C", "DF GC", "S AA")
amount <- c(3, 2, 1)

plot_data <- data.frame(category, amount)

plot_data %>%
  mutate(category = str_wrap(category, 1)) %>%
  ggplot(aes(category, amount))  
  geom_col()

Created on 2022-05-07 by the reprex package (v2.0.1)

  • Related