简体   繁体   中英

R: Subscript in the axis labels of a plotcorr plot

I am using the ellipse package, which creates fantastic correlation plots. However, label names are directly taken from column and row names.

This complicates the editing of the labels. I would like to have subscripts in my labels (eg k[A1], K[A],..) but I cannot figure out a way how to do it.

Here is my code:

library(ellipse)
library(RColorBrewer)

my_colors <- brewer.pal(5, "RdYlBu")
my_colors=colorRampPalette(my_colors)(100)

Data=rbind(c( 1.00000000,  0.35681412,  0.86504267),
           c(0.35681412,  1.00000000,  0.32562542),
           c(0.86504267,  0.32562542,  1.00000000))

rownames(Data) = c("kA1", "KA", "kA2")
colnames(Data) = c("kA1", "KA", "kA2")
plotcorr(Data , col=my_colors[Data*50+50] , mar=c(1,1,1,1), cex.axis=1.7, cex.lab=1.8, lwd=4)

Any ideas on how to edit the labels?

Maybe someone else has a better answer, but I would suggest using corrplot instead as it allows plotmath expressions. This gives me:

library(ellipse)
library(RColorBrewer)
library(corrplot)
my_colors <- brewer.pal(5, "RdYlBu")
my_colors=colorRampPalette(my_colors)(100)
Data=rbind(c( 1.00000000,  0.35681412,  0.86504267),
       c(0.35681412,  1.00000000,  0.32562542),
       c(0.86504267,  0.32562542,  1.00000000))
rownames(Data) = c(":k[A1]", ":K[A]", ":k[A2]")
colnames(Data) = c(":k[A1]", ":K[A]", ":k[A2]")
corrplot(Data , method= "ellipse", col=my_colors[Data*50+50], mar=c(1,1,1,1), cex.axis=1.7, cex.lab=1.8)

Which then looks like this (you can still tweak it a bit to look nicer):

在此处输入图片说明

If you are set on using plotcorr you can probably try some roundabout way using text such as:

text(1:3, 4, expression("k"[A1], "K"[A], "k"[A2]))
text(0, 3:1, expression("k"[A1], "K"[A], "k"[A2]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM