[英]Text and second line is not being displayed with plot() and line()
當我正在顯示我的文字中沒有source
我在RStudio代碼。 而且第二行也沒有顯示。 我不確定為什么會這樣。 我的向量alphas
, acc_3
和acc_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_1和acc_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.