【问题标题】:Legend not showing in R Plot [closed]R图中未显示图例[关闭]
【发布时间】:2021-10-13 06:45:47
【问题描述】:

我创建了以下情节,但我的传说消失了。它之前工作过,但突然它不会显示... 我已经尝试重新启动会话并重写函数,但这并没有改变任何东西。

USDT_chart = plot(btc_daily_return, lwd= 0.7, col = "darkgrey",type='l', ylab = "Returns", main="Daily returns of Tether")
lines(usdt_daily_return,lty=2,lwd=1,col="red")
lines(eurusd_daily_return, lty = 1, lwd = 0.8, col = "blue")
legend("bottomleft", inset=0.05, legend = c("USDT", "BTC", "EUR/USD"), col = c("red", "darkgrey", "blue"), lty = 1)

有人知道这可能是什么原因吗? 谢谢!

【问题讨论】:

  • 尝试使用x11() 在新窗口中绘图,有时 r studio 中的绘图窗口有点错误
  • 我们没有您的数据,所以很难说出了什么问题。您能否包含或生成具有相同问题的数据,以使您的结果具有可重复性?

标签: r plot legend


【解决方案1】:

尝试将xpd=TRUE 添加到图例中: 默认情况下,图例被绘图区域截断。此 xpd 参数可以在绘图区域之外进行绘图。参见例如?par 了解有关 xpd 的更多信息。

在这里学习:Legend disappaers when plotting in R

USDT_chart = plot(btc_daily_return, lwd= 0.7, col = "darkgrey",type='l', ylab = "Returns", main="Daily returns of Tether")
lines(usdt_daily_return,lty=2,lwd=1,col="red")
lines(eurusd_daily_return, lty = 1, lwd = 0.8, col = "blue")
legend("bottomleft", inset=0.05, legend = c("USDT", "BTC", "EUR/USD"), 
       col = c("red", "darkgrey", "blue"), lty = 1, xpd=TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 2018-05-09
    • 2013-06-09
    • 2016-07-23
    • 1970-01-01
    • 2016-07-19
    • 2014-10-16
    相关资源
    最近更新 更多