9 Replies Latest reply: Feb 10, 2017 3:21 PM by Steve Dark

# Drawing a straight line through points using R

Hi,

I've got R integration set up with Qlik Sense Desktop and all seems to be working okay.  The example QVFs work fine and I have been able to send in two arguments and multiply them.

Unfortunately, I don't have any prior experience of using R.

Can anyone please advise how I can go about drawing a straight line through a set of values on a line chart?

Further to that, can someone advise how to extend that line n dimension values into future?

Steve

• ###### Re: Drawing a straight line through points using R

Just found someone that knows a bit of R in the building, have come up with this:

R.ScriptEval('lm(.arg2~.arg1)\$fitted.values',Dim,Value)

And this:

R.ScriptEval('

a=.arg1

b=.arg2

lm1=lm(b~a)

predict(lm1,data.frame(a=seq(1,200,1)))

',Dim,Value)

Both seem to work well.

• ###### Re: Drawing a straight line through points using R

Thanks for posting this Steve - very helpful for jumpstarting the process.

Martin

• ###### Re: Drawing a straight line through points using R

Hi Steve,

Do you have any idea to calculate R² (R.squared)

Thanks!

• ###### Re: Drawing a straight line through points using R

Hi Yves,  What is R in this context?  Is it a field?  If so it is just R*R.  If you are aggregating you will need a sum around it, e.g. sum(R*R).

Sorry if I have missed the point?

• ###### Re: Drawing a straight line through points using R

Hi Steve,

R² ist a coefficient(variance) of regression in statistic,

you can use for it the function Linest_R2 in Qlik and in R: summary(lm(a~b))\$r.squared. I tried to calculate this measure in a KPI-Chart with R but i didn't get it

• ###### Re: Drawing a straight line through points using R

I thought I was probably missing something - should have taken the time to Google, it's been one of those days though.

Have you got any output from R coming into your app?  Does the simple straight line work for you?

• ###### Re: Drawing a straight line through points using R

What extension are you using that gives you the ability to evaluate R scripts from QS?

• ###### Re: Drawing a straight line through points using R

It's beta functionality, which is in the product already but is not publicly documented.  You also need to install a plug in which is not yet publicly available.

Hopefully it will be ready for prime-time soon, and I will try to remember to post back to this thread when it is.

Steve