Getting legend out of the plot in chart.TimeSeries in R -


suppose have following data:

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")) 

i figured out suitable way plot data use chart.timeseries function performanceanalytics package. did using :

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

and got:

enter image description here

my question how legend outside plot right. tried reproduce same chart using ggplot failed.

try this:

chart.timeseries(data, legend.loc = null) 

then add custom legend:

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")) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -