[R] Split charts with ggplot2, tidyquant

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Jan 18 22:24:06 CET 2018


If you don't want to wait for a ggplot2 solution, here are two
alternatives you can use right now:

chartSeries(SPYxts)
# or (with xts > 0.10
plot(SPYxts$SPY.Close)
addSeries(SPYxts$SPY.Volume, type = "h")

You might also try autoplot.zoo(), though I've never used it.




On Thu, Jan 18, 2018 at 2:11 PM, Eric Berger <ericjberger at gmail.com> wrote:
> Hi Charlie,
> I am comfortable to put the data in any way that works best. Here are two
> possibilities: an xts and a data frame.
>
> library(quantmod)
> quantmod::getSymbols("SPY")  # creates xts variable SPY
> SPYxts <- SPY[,c("SPY.Close","SPY.Volume")]
> SPYdf  <- data.frame(Date=index(SPYxts),close=as.numeric(SPYxts$SPY.Close),
>                      volume=as.numeric(SPYxts$SPY.Volume))
> rownames(SPYdf) <- NULL
>
> head(SPYxts)
> head(SPYdf)
>
> #           SPY.Close SPY.Volume
> #2007-01-03    141.37   94807600
> #2007-01-04    141.67   69620600
> #2007-01-05    140.54   76645300
> #2007-01-08    141.19   71655000
> #2007-01-09    141.07   75680100
> #2007-01-10    141.54   72428000
>
> #        Date  close   volume
> #1 2007-01-03 141.37 94807600
> #2 2007-01-04 141.67 69620600
> #3 2007-01-05 140.54 76645300
> #4 2007-01-08 141.19 71655000
> #5 2007-01-09 141.07 75680100
> #6 2007-01-10 141.54 72428000
>
> Thanks,
> Eric
>
>
>
> On Thu, Jan 18, 2018 at 8:00 PM, Charlie Redmon <redmonc at gmail.com> wrote:
>
>> Could you provide some information on your data structure (e.g., are the
>> two time series in separate columns in the data)? The solution is fairly
>> straightforward once you have the data in the right structure. And I do not
>> think tidyquant is necessary for what you want.
>>
>> Best,
>> Charlie
>>
>> --
>> Charles Redmon
>> GRA, Center for Research Methods and Data Analysis
>> PhD Student, Department of Linguistics
>> University of Kansas
>> Lawrence, KS, USA
>>
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2018 | www.rinfinance.com



More information about the R-help mailing list