Error plotting a zoo object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error plotting a zoo object

Rmetrics mailing list
Hello
My code is:

library(quantmod)library(tseriesChaos)library(nonlinearTseries)library(zoo)library(ggplot2)
bist100 <- getSymbols("XU100.IS", from="2011-01-01")
bist100 <- XU100.IS$XU100.IS.Close
bist100na <- na.approx(bist100)
bist100norm <- (bist100na - (min(bist100na)))/(max(bist100na) - min(bist100na))
my_rqa_det <- function(mydata) {  rqa.analysis=rqa(time.series = mydata, embedding.dim=11, time.lag=1,                   radius=0.05,lmin=2,do.plot=FALSE,distanceToBorder=2)  mydet <- rqa.analysis$DET  return(mydet)}
rollbist100norm<- rollapply(bist100norm, 260, my_rqa_det, by.column = TRUE,                             align = "right")
rollbist100normna <- na.omit(rollbist100norm)
ggplot(rollbist100normna, aes(x = date, y = det)) + geom_line()


I tried to plot "rollbist100normna" in the last line but I got the following error:


Don't know how to automatically pick scale for object of type function. Defaulting to continuous.Don't know how to automatically pick scale for object of type function. Defaulting to continuous.Error: Columns `x`, `y` must be 1d atomic vectors or listsCall `rlang::last_error()` to see a backtrace


How can I fix this problem?
Best regards.
Baki




        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Error plotting a zoo object

Joshua Ulrich
Hi Baki,

Please follow the posting guide and use plain text.  Your HTML message was
mangled.

Here's a simple example that reproduces the behavior:
library(quantmod)
library(ggplot2)
bist100 <- getSymbols("XU100.IS", from="2011-01-01")
bist100 <- Cl(XU100.IS)
bist100na <- na.approx(bist100)
ggplot(bist100na, aes(x = date, y = XU100.IS.Close)) + geom_line()

You get an error because "date" is a function in 'base'.

You can either use 'autoplot()`:
autoplot(bist100na)

Or you can fortify the object yourself, but then you have to name the `x`
and `y` columns correctly.  By default, the xts/zoo index is put in a
column named "Index".  So the ggplot() call would look like:
ggplot(fortify(bist100na), aes(x = Index, y = XU100.IS.Close)) + geom_line()

It is also very easy to use xts or zoo plotting via the plot() function:
plot(bist100na)

Hope that helps.

Best,
Josh


On Thu, Nov 15, 2018 at 5:34 PM Baki UNAL via R-SIG-Finance <
[hidden email]> wrote:

> Hello
> My code is:
>
>
> library(quantmod)library(tseriesChaos)library(nonlinearTseries)library(zoo)library(ggplot2)
> bist100 <- getSymbols("XU100.IS", from="2011-01-01")
> bist100 <- XU100.IS$XU100.IS.Close
> bist100na <- na.approx(bist100)
> bist100norm <- (bist100na - (min(bist100na)))/(max(bist100na) -
> min(bist100na))
> my_rqa_det <- function(mydata) {  rqa.analysis=rqa(time.series = mydata,
> embedding.dim=11, time.lag=1,
>  radius=0.05,lmin=2,do.plot=FALSE,distanceToBorder=2)  mydet <-
> rqa.analysis$DET  return(mydet)}
> rollbist100norm<- rollapply(bist100norm, 260, my_rqa_det, by.column =
> TRUE,                             align = "right")
> rollbist100normna <- na.omit(rollbist100norm)
> ggplot(rollbist100normna, aes(x = date, y = det)) + geom_line()
>
>
> I tried to plot "rollbist100normna" in the last line but I got the
> following error:
>
>
> Don't know how to automatically pick scale for object of type function.
> Defaulting to continuous.Don't know how to automatically pick scale for
> object of type function. Defaulting to continuous.Error: Columns `x`, `y`
> must be 1d atomic vectors or listsCall `rlang::last_error()` to see a
> backtrace
>
>
> How can I fix this problem?
> Best regards.
> Baki
>
>
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>


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

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.