我有以下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')
Run Code Online (Sandbox Code Playgroud)
为什么我的传说没有显示?
通过编码,您已将字符向量分配给名为的对象legend。
为了添加图例,您需要使用该legend()功能。
legend(x = 10, y = 4e5,
col = c("black", "red"), lty = 1, lwd = 1,
legend = c('Human Data', 'Actual Prices'))
Run Code Online (Sandbox Code Playgroud)
您可以使用启发式方法,方法是更改和中的值x,y直到找到所需的位置。或者,您也可以设置x为几个预定义值之一:
legend(x = "top",
col = c("black", "red"), lty = 1, lwd = 1,
legend = c('Human Data', 'Actual Prices'))
Run Code Online (Sandbox Code Playgroud)
其他选项设置x为“底部”,“底部”,“底部左”,“左侧”,“顶部左”,“顶部右”,“右侧”或“中心”。
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |