change the orientation of x axis labels to vertical in ggplotw in r

To change the orientation of x axis labels to vertical in ggplot2 in R, you can use the theme() function with the element_text() function. Here's how you can do that:

main.r
library(ggplot2)

# create a sample plot
p <- ggplot(mtcars, aes(x = mpg, y = wt)) +
  geom_point()

# rotate x axis labels to vertical
p + theme(
  axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)
)
212 chars
11 lines

In the above example, the angle argument specifies the angle of the text, vjust specifies the vertical justification (0.5 centers the text vertically), and hjust specifies the horizontal justification (1 aligns the text to the right of the plot panel). You can adjust these arguments to suit your needs.

gistlibby LogSnag