簡體   English   中英

文本和第二行未與plot()和line()一起顯示

[英]Text and second line is not being displayed with plot() and line()

當我正在顯示我的文字中沒有source我在RStudio代碼。 而且第二行也沒有顯示。 我不確定為什么會這樣。 我的向量alphasacc_3acc_1內都有值。

alphas = c(0.050, 0.075, 0.100, 0.150, 0.175, 0.200, 0.225, 0.250, 0.275, 0.300)
acc_1 = c(0.9997631, 0.9999210, 0.9995263, 0.9980261, 1.0000000, 0.9996052, 1.0000000, 0.9999210, 1.0000000, 0.9996052)
acc_3 = c(0.9526814, 0.9626709, 0.9563617, 0.9447950, 0.9616193, 0.9600421, 0.9521556, 0.9505783, 0.9490011, 0.9463722)  
plot(alphas, acc_1, type="l", xlab="Alpha", ylab="Acc", col="red")
lines(alphas, acc_3, col="green")

在此處輸入圖片說明

我們需要設置Y限制,因此它包括acc_1acc_3的值:

myYlim <- range(c(acc_1, acc_3))

plot(alphas, acc_1, type = "l", xlab = "Alpha", ylab = "Acc", col = "red", ylim = myYlim)
lines(alphas, acc_3, col = "green")

在此處輸入圖片說明


使用matplot (如@thelatemail在評論中所建議):

matplot(alphas, cbind(acc_1,acc_3),
        type = "l", lty = 1, col = c("red", "green"), ylab = "value")

將一個矩陣的列與另一個矩陣的列相對應。

在此處輸入圖片說明


或者使用ggplot ,准備整潔的數據,然后繪制:

library(dplyr)
library(tidyr)
library(ggplot2)

plotDat <- data.frame(alphas, acc_1, acc_3) %>% 
  gather(key = "acc", value = "value", -alphas)

ggplot(plotDat, aes(alphas, value, col = acc)) +
  geom_line()

在此處輸入圖片說明

暫無
暫無

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

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