繁体   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