在我的皮尔逊相关图中,我很难给化学名称加上下标.如果有人能帮上忙,那就太棒了:

colnames(JO_数据) = c("CO2","Cumulative CO2", "N2O", "Cumulative N2O", "pH", "pH (CaCl2)", "EC", "MBC", "NH4", "NO3")

library(metan)

corrl <- corr_coef(JO_数据)

plot(corrl)

Image of Pearsons correlation graph

> str(JO_数据)
'data.frame':   288 obs. of  10 variables:
 $ CO2           : num  0.517 0.448 0.593 0.627 1.211 ...
 $ Cumulative CO2: num  0.517 0.448 0.593 0.627 1.211 ...
 $ N2O           : num  0.0264 0.0241 0.0298 0.0338 0.0644 ...
 $ Cumulative N2O: num  0.0264 0.0241 0.0298 0.0338 0.0644 ...
 $ pH            : num  5.9 5.94 5.98 5.95 6.1 6.09 6.12 6.11 5.87 6.06 ...
 $ pH (CaCl2)    : num  5.18 5.18 5.18 5.18 5.34 5.34 5.34 5.34 5.33 5.35 ...
 $ EC            : num  90.9 87.4 79.7 88.9 147.4 ...
 $ MBC           : num  681 634 685 619 633 ...
 $ NH4           : num  10 8 7.6 24.7 158.3 ...
 $ NO3           : num  20.5 21.6 19.4 17.7 60.8 55.8 59.7 54 19.8 21.5 ...

数据

JO_数据 <- structure(list(CO2 = c(0.517359932, 0.447990483, 0.593061985, 
0.627331461, 1.21050112, 1.209451298), `Cumulative CO2` = c(0.517359932, 
0.447990483, 0.593061985, 0.627331461, 1.21050112, 1.209451298
), N2O = c(0.02643275, 0.02407505, 0.02975459, 0.03384935, 0.0643722, 
0.06104556), `Cumulative N2O` = c(0.02643275, 0.02407505, 0.02975459, 
0.03384935, 0.0643722, 0.06104556), pH = c(5.9, 5.94, 5.98, 5.95, 
6.1, 6.09), `pH (CaCl2)` = c(5.18, 5.18, 5.18, 5.18, 5.34, 5.34
), EC = c(90.88, 87.4, 79.74, 88.86, 147.4, 146.2), MBC = c(680.706103, 
634.1018757, 684.5231352, 618.7922904, 632.797167, 649.4327767
), NH4 = c(10, 8, 7.6, 24.7, 158.3, 132.6), NO3 = c(20.5, 21.6, 
19.4, 17.7, 60.8, 55.8)), row.names = c(NA, 6L), class = "data.frame")

推荐答案

这有点麻烦,但它处理了示例数据集中的所有情况.使用自定义标签器将每个数字转换为下标以创建表达式.主要的技巧是,表达式末尾或右括号前的下标不需要*,但在内部需要*.

library(stringr); library(scales) # pkg:metan must have attached pkg:ggplot2
make_subscripts <- function(x){
  x <- str_replace_all(string = x,
                        pattern = "([0-9]+)(?=\\w)", #Internal numbers
                        replacement = "[\\1]*")
  x <- str_replace_all(x, 
                       pattern = "([0-9]+)(?=$|[)])", #End numbers
                       replacement = "[\\1]")
  x <- str_replace_all(x,
                       pattern = "\\s", #Spaces
                       replacement = "~")
  x
}

plot(corrl) + 
  scale_x_discrete(labels = \(x)parse(text = make_subscripts(x))) +
  scale_y_discrete(position = "right",
                   labels = \(x)parse(text = make_subscripts(x)))

enter image description here

R相关问答推荐

编码变量a、b、c以匹配来自另一个数据点的变量x

从嵌套列表中智能提取线性模型系数

R等效于LABpascal(n,1)不同的列符号

从一个列表的框架中移除列表包装器

使用`Watch()`和`renderUI()`时,不再满足仍出现在SHILINY AFTER条件中的条件输入

R-按最接近午夜的时间进行筛选

跨列查找多个时间报告

在多页PDF中以特定布局排列的绘图列表不起作用

如何将一个方阵分解成没有循环的立方体

手动指定从相同数据创建的叠加图的 colored颜色

远离理论值的伽马密度曲线下面积的近似

计算使一组输入值最小化的a、b和c的值

如何在Quarto中使用美人鱼图表中的标记来加粗文本

在同一单元格中创建包含整数和百分比的交叉表

在鼠标悬停时使用Plotly更改geom_point大小

识别部分重复行,其中一行为NA,其重复行为非NA

我有2011-2022年的年度数据.如何计算最低年份和最高年份之间的差额?

根据部分名称匹配获取多组列的行求和

如何 suppress 条形图中的零条?

R-有没有办法比较列字符串之间的单个项目?