修改变量名称

问题描述 投票:0回答:1

我正在尝试修改变量标签,即我的变量“h_ex”代表“家庭开支”,我希望在进行corplor时出现“家庭开支”,以及如何将这些更改应用于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)
r ggplot2 correlation r-corrplot
1个回答
2
投票

您可以重命名数据集中的变量。标签只是变量名称。这是一个首先使用

mtcars
的示例,不更改名称,然后更改几个变量名称。

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')

创建于 2023-10-26,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.