cancel
Showing results for 
Search instead for 
Did you mean: 

Creating plots with R

Nick_Mospan
New Contributor II
I'm trying to chart my data using R directly from q. The plot is opening up but the window is not responsive, can't be resized and it's marked as (Not Responding) by windows. I can close it by running dev.off() but it won't open up straight away the second time, requires some luck.
I tried both rserver where I load R directly into q process and rserve where q connects to R process. Both behave the same.

My code is

\l rinit.q
Ropen 0
data:([time:.z.d+til 100] price:10+sums 100?0.01 -0.01)
Rset["data";data]
Rcmd["plot(data$time,data$price,type=\"l\",xlab=\"time\",ylab=\"price\")"]
Rcmd["dev.off()"]


I'm using kdb 3.3 and R 3.3.3, both running on Windows.

What am I doing wrong?

Ideally I would like R to create a window with a plot and then update it every time I run Rcmd["plot(..)"]. It's just for research and visualizing my data.

Thanks
2 REPLIES 2

sergey
New Contributor
Does this example work for you?
https://github.com/KxSystems/cookbook/blob/master/r/rserver/examples/pcd.q

Nick_Mospan
New Contributor II
Thanks mate, this helps a lot. I suspected that you need to run a message loop somehow to get it working.
I did not realize that you need to print the plot to get it open in a browser. Now my dygraph charts work, this is awesome.

Cheers
Nick