如何将自定义文本添加到 R 中的四重图?
How to add a custom text to a fourfoldplot graph in R?
我正在尝试向图形添加附加信息,该图形是 R 中函数 fourfoldplot
的输出。此函数绘制意外事件 table。问题是我需要向情节的每个部分添加信息。我试过使用 text
和 mtext
但没有成功。
它们都需要文本在 x
和 y
中的位置(或通过单击绘图定义位置)。但是这个图没有 x 和 y,因为它是一个馅饼(或者我找不到它们)。另一件增加复杂性的事情是我需要在一页上制作多个图表。
这是我的数据样本data1
#dput(data1)
list(structure(c(159076L, 5858L, 7285L, 23571L), .Dim = c(2L,
2L), .Dimnames = list(Prediction = c("O3<80", "O3>80"), Reference = c("O3<80",
"O3>80")), class = "table"), structure(c(159385L, 5549L, 6679L,
24177L), .Dim = c(2L, 2L), .Dimnames = list(Prediction = c("O3<80",
"O3>80"), Reference = c("O3<80", "O3>80")), class = "table"),
structure(c(159273L, 5661L, 8985L, 21871L), .Dim = c(2L,
2L), .Dimnames = list(Prediction = c("O3<80", "O3>80"), Reference = c("O3<80",
"O3>80")), class = "table"), structure(c(159250L, 5684L,
8486L, 22370L), .Dim = c(2L, 2L), .Dimnames = list(Prediction = c("O3<80",
"O3>80"), Reference = c("O3<80", "O3>80")), class = "table"))
我使用了以下脚本来绘制:
par(mfrow=c(2,2))
for(pltnum in 1:length(data)) {
fourfoldplot(data1[[pltnum]],
color = c("#B22222", "#2E8B57"),
main = "")
}
以上脚本的输出是:
我想要的输出是:
非常感谢任何帮助。
这可以给你你想要的。您可以使用 (x,y)
值的不同值来将文本注释准确定位到您想要的位置。
for(pltnum in 1:length(data)) {
fourfoldplot(data1[[pltnum]],
color = c("#B22222", "#2E8B57"),
main = "") +
text(-0.4,0.4, "TN", cex=1) +
text(0.4, -0.4, "TP", cex=1) +
text(0.4,0.4, "FN", cex=1) +
text(-0.4, -0.4, "FP", cex=1)
}
输出
我正在尝试向图形添加附加信息,该图形是 R 中函数 fourfoldplot
的输出。此函数绘制意外事件 table。问题是我需要向情节的每个部分添加信息。我试过使用 text
和 mtext
但没有成功。
它们都需要文本在 x
和 y
中的位置(或通过单击绘图定义位置)。但是这个图没有 x 和 y,因为它是一个馅饼(或者我找不到它们)。另一件增加复杂性的事情是我需要在一页上制作多个图表。
这是我的数据样本data1
#dput(data1)
list(structure(c(159076L, 5858L, 7285L, 23571L), .Dim = c(2L,
2L), .Dimnames = list(Prediction = c("O3<80", "O3>80"), Reference = c("O3<80",
"O3>80")), class = "table"), structure(c(159385L, 5549L, 6679L,
24177L), .Dim = c(2L, 2L), .Dimnames = list(Prediction = c("O3<80",
"O3>80"), Reference = c("O3<80", "O3>80")), class = "table"),
structure(c(159273L, 5661L, 8985L, 21871L), .Dim = c(2L,
2L), .Dimnames = list(Prediction = c("O3<80", "O3>80"), Reference = c("O3<80",
"O3>80")), class = "table"), structure(c(159250L, 5684L,
8486L, 22370L), .Dim = c(2L, 2L), .Dimnames = list(Prediction = c("O3<80",
"O3>80"), Reference = c("O3<80", "O3>80")), class = "table"))
我使用了以下脚本来绘制:
par(mfrow=c(2,2))
for(pltnum in 1:length(data)) {
fourfoldplot(data1[[pltnum]],
color = c("#B22222", "#2E8B57"),
main = "")
}
以上脚本的输出是:
我想要的输出是:
非常感谢任何帮助。
这可以给你你想要的。您可以使用 (x,y)
值的不同值来将文本注释准确定位到您想要的位置。
for(pltnum in 1:length(data)) {
fourfoldplot(data1[[pltnum]],
color = c("#B22222", "#2E8B57"),
main = "") +
text(-0.4,0.4, "TN", cex=1) +
text(0.4, -0.4, "TP", cex=1) +
text(0.4,0.4, "FN", cex=1) +
text(-0.4, -0.4, "FP", cex=1)
}