I am trying to make a correlation plot from the correlation matrix using corrplot function.
But I am getting a squeezed and unreadable plot. Also,the plot is generated at the extreme right end of the window. Ways of expanding a ggplot plot is not working here.
> col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))
> corrplot(correlation_matrix, method="color", col=col(200),
type="upper", order="hclust",
addCoef.col = "black", # Add coefficient of correlation
tl.col="black", tl.srt=45, #Text label color and rotation
# hide correlation coefficient on the principal diagonal
diag=FALSE
)
Here is the plot generated

As somebody suggested above, you should either repair the names you have or change the parameters of your plot. I will use ggcorrplot instead because I find it easier to work with (and better looking), but the illustration will show the same problem. If I switch out the names for the airquality data to be hideous like so and plot it:
#### Libraries ####
library(tidyverse)
library(ggcorrplot)
#### Change Data Names ####
bad.names <- airquality %>%
rename(Approximate_Ozone_Measurement_in_Some_Measure = Ozone,
Solar_Radiation_Based_On_Sun_Movements = Solar.R,
Wind_Barometer_Ratings_And_Such = Wind,
Temperature_In_Fahrenheit_To_Nearest_Degree = Temp)
#### Run Correlation ####
bad.corr <- bad.names %>%
correlation()
#### Plot ####
ggcorrplot(bad.corr)
You get something like this:

There are two ways around this...either rename your variables or rotate the names in some way to fix the angle so its readable. Its much easier with ridiculous names like this to simply fix them rather than squeeze them in artificially:
#### Fix Names ####
good.names <- bad.names %>%
rename(Ozone= Approximate_Ozone_Measurement_in_Some_Measure,
Solar.R = Solar_Radiation_Based_On_Sun_Movements,
Wind = Wind_Barometer_Ratings_And_Such,
Temp = Temperature_In_Fahrenheit_To_Nearest_Degree)
#### Run Correlation ####
good.corr <- good.names %>%
correlation()
#### Replot ####
ggcorrplot(good.corr,
lab = T,
type = "lower")

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With