How do I add axis labels to a ggcorrplot? I have a plot of the correlation between two separate attempts at a questionnaire. X axis represents the first attempt, Y axis represents the second attempt. I want to label the axes to show that this is what is being represented here.
My code looks like this:
corrQData <- round(cor(Attempt1, Attempt2), digits = 1)
ggcorrplot(corrQData,
outline.color = "white",
ggtheme = theme_bw(),
colors = c("#F8696B", "#FFEB84", "#63BE7B"),
legend.title = "Correlation",
lab = TRUE,
lab_size = 3,
tl.cex = 8,
tl.srt = 0,
title = "Correlation Between Questionnaire Attempts") +
theme(plot.title = element_text(hjust = 0.5, size=10), legend.title = element_text(size = 10))
My plot looks like this:
I tried adding + scale_x_discreet(name = "Attempt 1")
to the end of my ggcorrplot code but it didn't do anything.
You have to override the default behaviour of ggcorrplot
which is not to display axis labels. Do that by adding labels with ggplot2::labs()
(scale_x_discrete(name = ...)
works fine also) and changing the plot's theme
library(ggcorrplot)
corrdata <- round(cor(mtcars), 1)
ggcorrplot(corrdata) +
ggplot2::labs(x = 'X label', y = 'Y label') +
ggplot2::theme(
axis.title.x = element_text(angle = 0, color = 'grey20'),
axis.title.y = element_text(angle = 90, color = 'grey20')
)