簡體   English   中英

如何在R中的四折圖圖中添加自定義文本?

[英]How to add a custom text to a fourfoldplot graph in R?

我正在嘗試向圖中添加其他信息,該圖是R中函數fourfoldplot的輸出。此函數繪制列聯表。 問題是我需要向圖的每個扇區添加信息。 我嘗試使用textmtext但是沒有運氣。

它們都需要xy的文本位置(或通過單擊繪圖來定義位置)。 但是此圖沒有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 = "")
    }

上面腳本的輸出是: output_mine

我想要的輸出是: output_desired

任何幫助將不勝感激。

這可以給您您想要的。 您可能會使用(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)
}

產量

annotate_text

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM