Left-align labels in corrplot R

18 Views Asked by At

Assume a dataframe and a correlation plot

X <- data.frame("XXXYYY" = rnorm(100, 0, 1),
                "XY" = rnorm(100, 0, 1),
                "XXXY" = rnorm(100, 0, 1))
corrplot::corrplot(cor(X), method = "color", tl.col = "black")

is it possible, to left-align the labels on the y-axis as below?

enter image description here

1

There are 1 best solutions below

0
Carl On

Worth considering a ggplot approach where you would have a high degree of control over all aspects of the plot including left-alignment of the y-axis text:

X <- data.frame("XXXYYY" = rnorm(100, 0, 1),
                "XY" = rnorm(100, 0, 1),
                "XXXY" = rnorm(100, 0, 1))

library(tidyverse)
library(corrr)

X |> 
  correlate() |> 
  pivot_longer(-term) |>
  ggplot(aes(term, name, fill = value)) + 
  geom_tile() +
  scale_x_discrete(position = "top") +
  labs(x = NULL, y = NULL)+
  theme(axis.text.y = element_text(hjust = 0))

Created on 2024-03-20 with reprex v2.1.0