我有一个简单的情节的以下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
设置为“bottomright”,“bottom”,“bottomleft”,“left”,“topleft”,“topright”,“right”或“center”。