santo
October 10, 2022, 7:55pm
1
I rotated my label to 270 degree but I can't align each letter to be vertical. I want the letters to be vertical and separated like there is a return after each text of a label. Below is my current code. Any help would be appreciated.
var1 <- c(10, 20, 30, 40)
var2 <- c(10, 12, 35, 40)
l <- c("A", "ABC", "CD", "CDE")
df <- data.frame(var1, var2, l)
ggplot(df, aes(x = var1, y = var2))+
geom_bar(stat="identity")+
geom_text(aes(y = var2 +5, label = l), angle = 270)
This approach adds a line break \n
after each letter. I also expanded the limits to be c(0, 50)
so the highest label would not be cut off.
library(tidyverse)
var1 <- c(10, 20, 30, 40)
var2 <- c(10, 12, 35, 40)
l <- c("A", "ABC", "CD", "CDE")
l = str_replace_all(l, '|', '\n')
df <- data.frame(var1, var2, l)
ggplot(df, aes(x = var1, y = var2))+
geom_bar(stat="identity")+
geom_text(aes(y = var2 +5, label = l)) +
scale_y_continuous(limits = c(0, 50))
Created on 2022-10-10 with reprex v2.0.2.9000
2 Likes
system
Closed
October 17, 2022, 8:40pm
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.