Modify names of variables

50 views Asked by At

I am trying to modify the variable labels, that is, my variable "h_ex" represents "household expenses", and I would like "household expenses" to appear when doing my corrplor, in addition to how these changes would be applied to the rest of the package ggplot?

corrplot(data, method = 'color', type = 'lower',tl.col = 'black',addCoef.col ='white', number.cex = 0.7, diag=FALSE, cl.pos = 'r')+ theme(axis.text = full_name_vars)
1

There are 1 answers

0
DaveArmstrong On BEST ANSWER

You can rename the variables in the dataset. The labels are simply the variable names. Here's an example with mtcars first, without changing names and then changing a couple of the variable names next.

library(corrplot)
library(dplyr)

corrplot(cor(mtcars), 
         method = 'color', 
         type = 'lower',
         tl.col = 'black',
         addCoef.col ='white', 
         number.cex = 0.7, 
         diag=FALSE, 
         cl.pos = 'r')



new_mtcars <- mtcars %>% 
  rename("Miles per Gallon" = mpg, 
         "# Cylinders" = cyl) %>% 
  select(where(is.numeric))
corrplot(cor(new_mtcars), 
         method = 'color', 
         type = 'lower',
         tl.col = 'black',
         addCoef.col ='white', 
         number.cex = 0.7, 
         diag=FALSE, 
         cl.pos = 'r')

Created on 2023-10-26 with reprex v2.0.2