How to Rotate Axis Labels in ggplot2?

[This article was first published on finnstats », and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Story 481794965

How to Rotate Axis Labels in ggplot2?.

Axis labels on graphs must occasionally be rotated.

Let’s look at how to rotate the labels on the axes in a ggplot2 plot. 

Let’s begin by creating a basic data frame and the plot.

Rotate Axis Labels in ggplot2

library(ggplot2)
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len,fill=factor(dose))) +
geom_boxplot()
p

Normality Test in R » How to Perform » Easy Steps »

Rotation based on vjust and hjust

p + theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

To ensure that the labels are close enough to the plot, you may need to alter the vjust and hjust values depending on the angle at which you rotate the labels.

Correlation Analysis in R? » Karl Pearson correlation coefficient »

Change axis tick mark labels

p + theme(axis.text.x = element_text(face = "bold", color = "red",
size = 12, angle = 45),
axis.text.y = element_text(face = "bold", color = "blue",
size = 12, angle = 45))

Remove x and y axis tick mark labels

Let’s Remove x and y-axis tick mark labels

How to measure the Statistics Quality Control Chart of the product?

p + theme(axis.text.x = element_blank(),  axis.text.y = element_blank())

Remove axis ticks and tick mark labels

p + theme(axis.text.x = element_blank(),  axis.text.y = element_blank(),
axis.ticks = element_blank())

One Sample Analysis in R » Quick Guide »

The post How to Rotate Axis Labels in ggplot2? appeared first on finnstats.

To leave a comment for the author, please follow the link and comment on their blog: finnstats ».

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)