rotate x axis title to 90 degress in ggplot in r

You can rotate the x-axis title to 90 degrees in ggplot in R by using the theme() function with the axis.text.x argument like this:

main.r
library(ggplot2)
# Example data
df <- data.frame(x = c("A", "B", "C"), y = c(10, 20, 15))

# Create the ggplot with rotated x-axis title
ggplot(df, aes(x, y)) + 
  geom_bar(stat = "identity") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
264 chars
9 lines

In the above code, angle = 90 rotates the x-axis title to 90 degrees. You can adjust the angle value as needed to achieve the desired rotation.

related categories

gistlibby LogSnag