R corrplot change data labels

后端 未结 1 826
悲&欢浪女
悲&欢浪女 2020-12-19 04:02

I am using R corrplot library. It looks amazing, however to produce a really good plot I want to change the labels of rows and columns of the correlation matrix.

On

1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 04:45

    In the current corrplot version 0.75, you cannot use labels parameter because the X and Y labels are computed within the corrplot() function from colnames() and rownames() of the input corr matrix.

    I'm using similar approach as you have suggested:

    M <- cor(mtcars)
    colnames(M) <- c("a", "set", "of", "x", "labels", 1:6)
    corrplot(M, method = "color")
    

    BTW, I linked this stackoverflow question from our github issue tracker: https://github.com/taiyun/corrplot/issues/20

    UPDATE: In the current corrplot version 0.78, also plotmath expressions are allowed in variable names. Just prefix your name with one of the characters ":", "=" or "$".

    Example:

    M <- cor(mtcars)[1:5,1:5]
    colnames(M) <- c("alpha", "beta", ":alpha+beta", ":a[0]", "=a[beta]")
    rownames(M) <- c("alpha", "beta", NA, "$a[0]", "$ a[beta]")
    corrplot(M)
    

    0 讨论(0)
提交回复
热议问题