[英]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'))
您可以通過改變x
和y
的值來使用啟發式方法,直到找到所需的位置為止。 或者,您也可以將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.