gpt4 book ai didi

r - 为化学名称添加下标并显示在我的 Pearsons 相关图中

转载 作者:行者123 更新时间:2023-12-02 18:03:19 26 4
gpt4 key购买 nike

我在 PIL 森相关图中无法标出化学名称。如果有人可以提供帮助,那就太好了:

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

library(metan)

corrl <- corr_coef(JO_Data)

plot(corrl)

Image of Pearsons correlation graph

> str(JO_Data)
'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_Data <- 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 - 为化学名称添加下标并显示在我的 Pearsons 相关图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73849680/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com