簡體   English   中英

R圖例未在圖中顯示

[英]R legend not showing in Plot

我有以下R代碼用於簡單繪圖:

ExperimentDataNames = c('Count', 'HumanData', 'ActualPrices')
ExperimentData <- read_csv("/Users/justin_chudley/desktop/ExperimentData.csv", col_names = ExperimentDataNames)

x <- Count <- ExperimentData$Count
y <- HumanData <- ExperimentData$HumanData
y1 <- ActualPrices <- ExperimentData$ActualPrices

plot(x,y, type = "l", xlab="Trial Number",ylab="$USD",main="Dow Jones Price vs Human Experiment")
lines(x,y1, type = "l", col=2)
legend=c('Human Data', 'Actual Prices') 

由於某些原因,圖例在此圖中完全不顯示: 在此處輸入圖片說明

為什么我的傳說沒有顯示?

通過編碼,您已將字符向量分配給名為legend的對象。

為了添加圖例,您需要使用legend()函數。

legend(x = 10, y = 4e5, 
       col = c("black", "red"), lty = 1, lwd = 1,
       legend = c('Human Data', 'Actual Prices'))

您可以通過改變xy的值來使用啟發式方法,直到找到所需的位置為止。 或者,您也可以將x設置為幾個預定義值之一:

legend(x = "top",
       col = c("black", "red"), lty = 1, lwd = 1,
       legend = c('Human Data', 'Actual Prices'))

其他選項是將x設置為“底部”,“底部”,“底部左”,“左側”,“頂部左”,“頂部右”,“右側”或“中心”。

暫無
暫無

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

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