2015-05-29 56 views
2

假設我有以下數據:獲得傳說敵人的陰謀在chart.TimeSeries R中

data<- structure(c(103.7, 103.2, 103.1, 105.4, 102.1, 103.5, 103.1, 
      102.6, 102.2, 104.6, -2.1, -1.4, -2.6, 1.9, -0.7, 1.4, -0.6, 
      -1.3, -1.4, 0, -25.3, -25.3, -25.3, -24.9, -24.7, -24.5, -21.4, 
      -20.9, -20.4, -19.8, 25, 20.7, 25.5, 19.8, 12.8, 13.6, 15.5, 
      23, 12.8, 16.3, -16.1, -20.1, -16.9, -17.8, -18.6, -19.5, -16.4, 
      -18.9, -16.1, -15.1), .Dim = c(10L, 5L), .Dimnames = list(NULL, 
      c("Edinburgh", "Glasgow", "Aberdeen", "St Andrews", 
      "Highlands")), .Tsp = c(1985, 1985.75, 12), class = c("mts", 
      "ts", "matrix")) 

我想通了,繪製我的數據最適合的方式是使用chart.TimeSeries功能從PerformanceAnalytics包。我這樣做,使用:

chart.TimeSeries(data, legend.loc = "right") 

和我:

enter image description here

我的問題是如何讓劇情到外面的傳說。我甚至嘗試使用ggplot重現相同的圖表,但失敗了。

+0

使用'legend.loc = NULL'然後添加使用'legend'功能自定義圖例。 –

+0

@TimBiegeleisen我試過這個,但是我怎麼才能讓圖例使用'chart.TimeSeries'生成的相同圖表顏色。 – athraa

回答

0

試試這個:

chart.TimeSeries(data, legend.loc = NULL) 

然後添加一個自定義的傳說:

legend(20,10, c("Edinburgh","Glasgow", "Aberdeen", "St Andrews", "Highlands"), 
lty=c(1,1), lwd=c(2.5,2.5), col=c("black", "red", "green", "deepskyblue", "blue")) 
+0

這將從圖中刪除圖例,但我仍然需要它。我只需要在右側但在劇情之外的相同傳說。 – athraa

+0

這個工作在你身邊嗎?即使在調整'x'和'y'座標之後,它似乎也不適用於我。 – athraa