R in GC

3,230 views
Skip to first unread message

Mark Liversedge

unread,
Apr 20, 2016, 3:47:38 PM4/20/16
to golden-cheetah-users
Hi,

The planning widget got usurped by a itch I had to use the R engine to support impulse-response modelling.
Anyway, as a results I've now created a chart type in GC to work with R.

It means we get to do some serious analytics inside GC with all the data available, using the 20+ years of R and libraries etc.



Above is an example of using the R lib ggplot2 to plot with it shown in a GC chart. (widget).
More meaningful stuff like model fitting and data mining are, of course, also possible.

I'm now working on the routines that access the GC data and config.

Cheers
Mark 

Ruud Goorden

unread,
Apr 21, 2016, 2:04:59 AM4/21/16
to golden-cheetah-users
Great work Mark! Very curious to try out this build

Mark Liversedge

unread,
Apr 23, 2016, 5:36:50 AM4/23/16
to golden-cheetah-users
Rather annoyingly RInside and Rcpp do not support MS Visual C and so we cannot support this on Windows
The whole QT5.6 mandating MSVC is rather a big problem and there is not a lot we can do about it*

Mark

* Yes I tried to circumvent this and build Rinside/Rcpp with gcc and link with MSVC, the headers/class templates break.

Mark Liversedge

unread,
Apr 24, 2016, 4:38:12 PM4/24/16
to golden-cheetah-users
On Saturday, 23 April 2016 10:36:50 UTC+1, Mark Liversedge wrote:
Rather annoyingly RInside and Rcpp do not support MS Visual C and so we cannot support this on Windows
The whole QT5.6 mandating MSVC is rather a big problem and there is not a lot we can do about it

I'm looking at replacing the code that uses RInside/Rcpp and doing it using QLibrary and the R API.
If MS can embed it in Visual Studio it must be possible, so will keep at it.

If you are on Windows and interested then MRO and VS looks really nice

Mark 

mike veloclinic

unread,
Apr 25, 2016, 9:22:42 PM4/25/16
to golden-cheetah-users
Mark,

Just letting you know the effort to get this done is appreciated. Thanks.

Mike

Ruud Goorden

unread,
Apr 26, 2016, 12:52:25 AM4/26/16
to golden-cheetah-users
Yes agree. It is really really great

Mark Liversedge

unread,
Apr 26, 2016, 3:13:28 AM4/26/16
to golden-cheetah-users
Cheers Mike,

The Windows support is technically quite challenging, but its fun to try and resolve.
Along the way I'm beginning to realise how useful it will be to have R available within GC.

I suspect we will use R more and more for charting.

Mark 

Matthieu Delcourt

unread,
Apr 29, 2016, 8:27:55 PM4/29/16
to golden-cheetah-users
Awesome! Will the R functionality be in the next development release?

Matt

Mark Liversedge

unread,
Apr 30, 2016, 2:19:14 AM4/30/16
to golden-cheetah-users
On Saturday, 30 April 2016 01:27:55 UTC+1, Matthieu Delcourt wrote:
Awesome! Will the R functionality be in the next development release?

Yes. Will post some example charts too to get things started

Mark 

Mark Liversedge

unread,
Apr 30, 2016, 3:17:35 AM4/30/16
to golden-cheetah-users
Apologies, I should have mentioned that windows support has been coded up.
Joern is looking at builds over the next few days, hopefully my code will work !

Will post a tutorial video sometime this weekend.

Cheers,
Mark 

Mark Liversedge

unread,
May 1, 2016, 4:12:59 PM5/1/16
to golden-cheetah-users
Have just added support for compare mode; you can get a list to plot with GC.activity(compare=TRUE).
If compare mode is active you get a list of rides, otherwise a list of 1 ride, the one currently selected.



Will look at compare date ranges tomorrow.
Mark

Mark Liversedge

unread,
May 1, 2016, 4:33:16 PM5/1/16
to golden-cheetah-users
On Sunday, 1 May 2016 21:12:59 UTC+1, Mark Liversedge wrote:
Have just added support for compare mode; you can get a list to plot with GC.activity(compare=TRUE).
If compare mode is active you get a list of rides, otherwise a list of 1 ride, the one currently selected.

If you're playing along, here is the chart script:

## R script will run on selection.

##

## GC.activity(compare=TRUE)

## GC.metrics(all=FALSE)

##

## Get the current ride or metrics

##


# get a list of activities, will have one member

# if not in compare mode, or multiple if we are

# in compare mode

d <- GC.activity(compare=TRUE)


## set plot limits

maxy <-0

maxx <- 0


for (compare in d) {


# get the activity being compared

ride <- compare$activity


# density

k <- density(ride$power)


# max on x axis

mx <- max(ride$power)

if (mx > maxx) maxx <- mx;


# max on y axis

my <- max(k$y)

if (my > maxy) maxy <- my;

}


## create a blank plot

plot(k, ylim = c(0,maxy), xlim=c(0,maxx), col="black",

main="", xlab="")


title(main="Power Distribution", xlab = "Watts")


## add density

for (compare in d) {


# just the ride

ride <- compare$activity


k <- density(ride$power)

lines(k, col=compare$color)

}


Mark 

Mark Liversedge

unread,
May 2, 2016, 5:04:56 AM5/2/16
to golden-cheetah-users
Added compare date ranges in R now.

So you can plot metrics and compare across seasons etc with R scripts.

Will look at mean max data next.



Here is the chart script:
## R script will run on selection.
##
## GC.activity(compare=FALSE)
## GC.metrics(all=FALSE,
##            compare=FALSE)
##
## Get the current ride or metrics
##

## get data
compares <- GC.metrics(compare=TRUE)

## ylim/xlim set
maxy <- 0
miny <- 0
maxx <- 0
minx <- 0


# loop through each looking for max min
for (compare in compares) {

   # get the metrics
   metrics <- compare$metrics

   # Duration on Y axis
   y <- max(metrics$Duration)
   if (y >maxy) maxy = y
   y <- min(metrics$Duration)
   if (y < miny) miny = y

   # Distance on X axis
   x <- max(metrics$Distance)
   if (x >maxx) maxx = x
   x <- min(metrics$Distance)
   if (x < minx) minx = x

}

# set first plot
plot(x=metrics$Distance, y=metrics$Duration,
     col="black", pch=20, main="", xlab="",
     ylim=c(miny,maxy), xlim=c(minx,maxx))

## now plot for real
for (compare in compares) {

    metrics <- compare$metrics
    points(x=metrics$Distance, y=metrics$Duration,
           col=compare$color, pch=20)

}

## title
title(main="Distance v Duration", xlab="Distance (km)",
      ylab="Duration (secs)")

Mark
Message has been deleted
Message has been deleted

Manuel Oberti

unread,
May 2, 2016, 8:35:22 AM5/2/16
to golden-cheetah-users
Thanks Mark , but in my GC 4.1604 appears this error : 

Error in GC.metrics(compare=TRUE) : unused argument (compare=TRUE)

THANKS
 

Mark Liversedge

unread,
May 2, 2016, 10:47:28 AM5/2/16
to golden-cheetah-users
Thanks Mark , but in my GC 4.1604 appears this error : 

Error in GC.metrics(compare=TRUE) : unused argument (compare=TRUE)

THANKS
 

The development builds contain the features that were available when they are built not when you install them.

Mark 

Manuel Oberti

unread,
May 3, 2016, 1:41:42 AM5/3/16
to golden-cheetah-users
Thanks Mark 

Mark Liversedge

unread,
May 3, 2016, 8:53:31 AM5/3/16
to golden-cheetah-users
Added GC.pmc(all=FALSE, metric="TSS") which returns a data.frame of date, stress, lts, sts, sb and rr.
You can specify the metric to use and of you want all values, or just for the date range selected.

I plotted TSB v IF historically to show correlation to better performances when SB around 0 (i.e. you have tapered).



CHEERS,
Mark


Mark Liversedge

unread,
May 4, 2016, 10:48:59 AM5/4/16
to golden-cheetah-users
I've added GC.activity.meanmax(compare=FALSE) and GC.activity.wbal(compare=FALSE).
Both work in compare mode obvs.

I assume that plotting meanmax is kinda obvious. But working with W'bal can get quite funky.
Here are 3 hills workouts of differing durations.



Mark

Stefan

unread,
May 4, 2016, 12:52:08 PM5/4/16
to golden-cheetah-users
Will it be possible to write back changes to activities? Perhaps like Macros in Excel?

One application could be to correct power readings. I own three powermeters: P1, P2M and Stages. I have a fairly strong left leg dominance. The dominance is not constant over the entire watt range. More bell shaped. I know the relationship from riding with my P1 pedals. Currently I correct my left-leg only measurements from the Stages outside of GC. I work directly on the json-files. It would be nice to do this in GC directly.

Another potential use case: after import of a fit file into GC I extract the powermeter serial and battery status fields from the fit file and write them into the json file externally.

Or use R for extended GIS analysis.

And these are just my ideas. I guess this would open up whole new world of options for GC. And all of this could be done with R. Of course, I do not know if is possible to extend the current development from charting to "macro scripting".

Just some idea, really appreciate all the effort you guys put into this.

Mark Liversedge

unread,
May 4, 2016, 1:01:57 PM5/4/16
to golden-cheetah-users
On Wednesday, 4 May 2016 17:52:08 UTC+1, Stefan wrote:
Will it be possible to write back changes to activities? Perhaps like Macros in Excel?

Absolutely.

I'm slowly adding functions, at present its all about getting the data in GC.
For sure next steps will be about creating and updating it too.

I think this is mostly going to be related to activity data and intervals.
We could also extend to use R for custom metrics and data processors.

Then we could start building analytic apps, with interactivity.
And the obvious step from there is to support user defined models and machine learning.

Who knows where it might go....

Mark 

Ruud Goorden

unread,
May 4, 2016, 2:43:14 PM5/4/16
to golden-cheetah-users
Is that in the spirit of: Some lead others follow? :)

Op woensdag 4 mei 2016 19:01:57 UTC+2 schreef Mark Liversedge:

Mark Liversedge

unread,
May 4, 2016, 2:58:20 PM5/4/16
to golden-cheetah-users
On Wednesday, 4 May 2016 19:43:14 UTC+1, Ruud Goorden wrote:
Is that in the spirit of: Some lead others follow? :)

Don't poke the bear.

And anyway, that's a stupid phrase since we all take turns to lead, and especially here.

GC is free software (as in freedom), that's it.

Everyone is free to contribute and participate. The R thing is a cool example; we get 20 years worth of contributions from a massive community ny baking it in, and it enables the wider GC community to participate and share in new and exciting ways.

CHEERS

Mark 

Ruud Goorden

unread,
May 4, 2016, 3:35:42 PM5/4/16
to golden-cheetah-users
Yes agree. Was just kidding, and I an sure such a small joke can be appreciated ;) It's all very nice to combine everything and taking steps further. Just downloaded 1604 and tried the changepoint plot. See if I can get some trackeR charts working next week. Cheers

Mark Liversedge

unread,
May 5, 2016, 5:07:21 AM5/5/16
to golden-cheetah-users
I've started to document this in the wiki with examples for those wanting to get started with it.
I'm documenting alongside the development so some of the features won't be in the DEV1604 build.


Mark

Chris Cleeland

unread,
May 5, 2016, 8:58:36 AM5/5/16
to Mark Liversedge, golden-cheetah-users
Great start at documentation!

Some important things that are missing (and if I knew I'd just add/submit):

- link to doc describing how to build GC with R integrated
- Is the R console referred to in the doc embedded in GC or is that using something like R Studio (or the standard R dist's console)?
- How does one create a chart rendered by R?  Even just something like "it's under the such-and-such menu", or a screenshot of the setup
- Brief description of the architecture of this integration from a user's point of view, e.g., GC is the data source, R performs analysis and transformations, feeding the results back into a plot in GC.  User accesses R from <where? need answer to questions above>.

I'm excited about this integration.

--
_______________________________________________
Golden-Cheetah-Users mailing list
golden-che...@googlegroups.com
http://groups.google.com/group/golden-cheetah-users?hl=en
---
You received this message because you are subscribed to the Google Groups "golden-cheetah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golden-cheetah-u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chris Cleeland

Mark Liversedge

unread,
May 5, 2016, 10:20:05 AM5/5/16
to golden-cheetah-users, liver...@gmail.com
On Thursday, 5 May 2016 13:58:36 UTC+1, Chris Cleeland wrote:
Great start at documentation!


Thanks Chris. I figured examples are more enlightening than pure API descriptions.
 
Some important things that are missing (and if I knew I'd just add/submit):

- link to doc describing how to build GC with R integrated

Probably leave that to developer lists etc like other stuff.
 
- Is the R console referred to in the doc embedded in GC or is that using something like R Studio (or the standard R dist's console)?

I should add a bit explaining the R Chart itself; canvas, console, script.

 
- How does one create a chart rendered by R?  Even just something like "it's under the such-and-such menu", or a screenshot of the setup

I definitely need to add something on enabling R chart in preferences (setting up RHOME)
 
- Brief description of the architecture of this integration from a user's point of view, e.g., GC is the data source, R performs analysis and transformations, feeding the results back into a plot in GC.  User accesses R from <where? need answer to questions above>.


Maybe later when its bedded in.
 
I'm excited about this integration.


Me too, it was a bit of a hack for fun originally and now its beginning to dawn on me that its quite a massive game changer. If you want an interesting chart then chances are R already has a package for it and you can knock it together in a few minutes.

No more waiting for a new release for a new chart type.. just write it in R............

Mark
 
On Thu, May 5, 2016 at 4:07 AM, Mark Liversedge <liver...@gmail.com> wrote:
I've started to document this in the wiki with examples for those wanting to get started with it.
I'm documenting alongside the development so some of the features won't be in the DEV1604 build.


Mark

--
_______________________________________________
Golden-Cheetah-Users mailing list

http://groups.google.com/group/golden-cheetah-users?hl=en
---
You received this message because you are subscribed to the Google Groups "golden-cheetah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golden-cheetah-users+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Chris Cleeland

Chris Cleeland

unread,
May 5, 2016, 10:33:29 AM5/5/16
to Mark Liversedge, golden-cheetah-users
On Thu, May 5, 2016 at 9:20 AM, Mark Liversedge <liver...@gmail.com> wrote:
On Thursday, 5 May 2016 13:58:36 UTC+1, Chris Cleeland wrote:
Great start at documentation!


Thanks Chris. I figured examples are more enlightening than pure API descriptions.
 
Some important things that are missing (and if I knew I'd just add/submit):

- link to doc describing how to build GC with R integrated

Probably leave that to developer lists etc like other stuff.

Based solely on my 30 minute old experience doing this from a recent pull, I'd suggest something like this:

<quote>
To use R, you'll need a build that has R enabled.  This minimally requires:
* R installed on development system and execution system
* GoldenCheetah's gcconfig.pri updated to have GC_WANT_R added to DEFINES
* full rebuild

Obviously there are more details, but this gives an overview.
</quote>
 
 
- Is the R console referred to in the doc embedded in GC or is that using something like R Studio (or the standard R dist's console)?

I should add a bit explaining the R Chart itself; canvas, console, script.

 
- How does one create a chart rendered by R?  Even just something like "it's under the such-and-such menu", or a screenshot of the setup

I definitely need to add something on enabling R chart in preferences (setting up RHOME)

It's not clear to me what that should be on a mac, or if it's even necessary.
 
I'm excited about this integration.


Me too, it was a bit of a hack for fun originally and now its beginning to dawn on me that its quite a massive game changer. If you want an interesting chart then chances are R already has a package for it and you can knock it together in a few minutes.

No more waiting for a new release for a new chart type.. just write it in R............

Is there an easy way to exchange scripts?


--
Chris Cleeland

Mark Liversedge

unread,
May 5, 2016, 10:46:58 AM5/5/16
to Chris Cleeland, golden-cheetah-users
On Thu, 5 May, 2016 at 3:33 PM, Chris Cleeland <chris.c...@gmail.com> wrote:
Is there an easy way to exchange scripts?

We're working on that !

The cloud db currently only supports metric trends charts, we're gonna update it to share ANY chart regardless of type.

Mark

Chris Cleeland

unread,
May 5, 2016, 5:18:10 PM5/5/16
to Mark Liversedge, golden-cheetah-users
So...I tried to add an R chart.  I can type in a title, but the gray box under the title doesn't appear to allow me to add any text.
--
Chris Cleeland

Mark Liversedge

unread,
May 5, 2016, 5:21:22 PM5/5/16
to golden-cheetah-users, liver...@gmail.com
On Thursday, 5 May 2016 22:18:10 UTC+1, Chris Cleeland wrote:
So...I tried to add an R chart.  I can type in a title, but the gray box under the title doesn't appear to allow me to add any text.

Do the dev builds have the same issue?
Note: do not use 5.6 with NOWEBKIT on a Mac, its very problematic.

Mark 

Mark Ewers

unread,
May 5, 2016, 5:23:36 PM5/5/16
to Chris Cleeland, Mark Liversedge, golden-cheetah-users
+1
I can see a little dark "More" drop down menu in the upper left-hand corner but I can't click on it and there is no way to enter text or copy/paste into the text into the text box
--
_______________________________________________
Golden-Cheetah-Users mailing list
golden-che...@googlegroups.com

http://groups.google.com/group/golden-cheetah-users?hl=en
---
You received this message because you are subscribed to the Google Groups "golden-cheetah-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golden-cheetah-u...@googlegroups.com.

Mark Liversedge

unread,
May 5, 2016, 5:25:20 PM5/5/16
to Mark Ewers, Chris Cleeland, golden-cheetah-users
Are you using the official builds ?

Chris Cleeland

unread,
May 5, 2016, 5:27:10 PM5/5/16
to Mark Liversedge, Mark Ewers, golden-cheetah-users
I am using a dev build built from commit 306ae970c7c88b57f2b2c756a607d04cd850a894

--
Chris Cleeland

Mark Liversedge

unread,
May 5, 2016, 5:27:22 PM5/5/16
to Mark Ewers, Chris Cleeland, golden-cheetah-users
Please make sure you have set R home in preferences
I posted a video outlining how to get things setup

Mark

Chris Cleeland

unread,
May 5, 2016, 5:30:13 PM5/5/16
to Mark Liversedge, Mark Ewers, golden-cheetah-users
What value should it be on a mac?  /Applications/R.app ?
--
Chris Cleeland

Karl Billeter

unread,
May 5, 2016, 8:12:11 PM5/5/16
to Chris Cleeland, golden-cheetah-users
On Thu, May 05, 2016 at 04:29:51PM -0500, Chris Cleeland wrote:

> What value should it be on a mac? /Applications/R.app ?

Whatever R.home() returns in R. I installed using MacPorts so for me

command_prompt$ Rscript -e 'R.home()' # gives
[1] "/opt/local/Library/Frameworks/R.framework/Resources"


Karl

Andrea Sabba

unread,
May 8, 2016, 2:50:58 AM5/8/16
to golden-cheetah-users
I've tried to add an R chart but I get an error message ad no plot at all: what's wrong?
See attached picture.

Thanks.
Andrea
Screenshot 2016-05-08 08.49.13.png

Mark Liversedge

unread,
May 8, 2016, 3:22:44 AM5/8/16
to golden-cheetah-users
The > in the examples is a line prompt -- you don't need to type it in.

Mark

Andrea Sabba

unread,
May 8, 2016, 3:28:58 AM5/8/16
to golden-cheetah-users
Ok, now it works.

Thanks Mark.
Andrea

Craig

unread,
May 12, 2016, 9:26:53 PM5/12/16
to golden-cheetah-users
For some reason I keep getting a could not find function "plot" error with any chart I try.  I had thought plot was a base command and did not need a package update.  R loads fine, it seems or at least using R.home() to set my folder worked well.  Any ideas what I' doing wrong here.  I imagine it's something small I've overlooked.  Really looking forward to learning to program in R, but I'm already stuck banging my head against the wall.  Thanks in advance.  Google has not helped me in this case.
Screen Shot 2016-05-12 at 9.15.12 PM.png

Martin Goikoetxea Conde

unread,
May 13, 2016, 9:28:43 AM5/13/16
to golden-cheetah-users
Hi,

I dont get "GC.season(all=TRUE)" work in console. I get this answer:



GC is running in Windows8.1 64bit in Spanish language

Thanks


Mark Liversedge

unread,
May 13, 2016, 7:38:04 PM5/13/16
to golden-cheetah-users
This is a repeat of the issue reported running v3.3.0 of R.
If you look closely you will also see 'par' is not found.

I've fixed the dynamic loading code so this will be fixed in the next dev build.
For now just install 3.2.4 of R, or wait a couple of weeks :)

Mark

Mark Liversedge

unread,
May 13, 2016, 7:40:19 PM5/13/16
to golden-cheetah-users
Its GC.metrics() as the new functions are not in the dev build.

Mark

Mark Liversedge

unread,
May 14, 2016, 5:16:31 AM5/14/16
to golden-cheetah-users
On Saturday, 14 May 2016 00:38:04 UTC+1, Mark Liversedge wrote:
I've fixed the dynamic loading code so this will be fixed in the next dev build.
For now just install 3.2.4 of R, or wait a couple of weeks :)

Have tested and now a build based on 3.2.4 will work with an install of 3.3.0.
We will now always use the version installed, to avoid version mismatches.

Heres a capture from Windows 10.



CHEERS

Mark 

Craig

unread,
May 14, 2016, 12:32:54 PM5/14/16
to golden-cheetah-users
Thanks Mark!
  Somehow I missed the previous posts about 3.3.

Simon Brewer

unread,
May 25, 2016, 12:04:54 AM5/25/16
to golden-cheetah-users
Hi Mark,

I was wondering how to escape out of infinite loops in R.  At the moment, it seems to hang GC, and the normal CTRL-C has no effect 

Simon

Mark Liversedge

unread,
May 25, 2016, 2:55:46 AM5/25/16
to golden-cheetah-users
Hmmm. I guess we need to find a way of interrupting a badly written script!
Will look at that.

In the meantime I'd reset with view->reset layout (but save away any that you want to keep first).
We've now implemented import/export for any chart, so that will help but its not in the current development build.

Mark

Simon Brewer

unread,
May 25, 2016, 3:00:24 AM5/25/16
to Mark Liversedge, golden-cheetah-users
Yes it happened to me surprisingly easily.  I was half way through writing a script, and clicked over to another activity to check something, which initiated the script.

Unfortunately the script was complete enough to hang :-)  Luckily I lost the script once I restarted so I wasn't stuck in an endless hang.

--
_______________________________________________
Golden-Cheetah-Users mailing list
golden-che...@googlegroups.com
http://groups.google.com/group/golden-cheetah-users?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "golden-cheetah-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golden-cheetah-users/Wv-JPlvBcrc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golden-cheetah-u...@googlegroups.com.

Karsten Walker

unread,
May 26, 2016, 5:53:31 PM5/26/16
to golden-cheetah-users, liver...@gmail.com
Neat stuff. I do most of my work in R as a living, but generally use RStudio as my IDE.  Given that I work a lot with machine learning and have access to high powered compute resources I am very curious as to performing some ML methods (clustering, nearest neighbor) on both rider and ride data in the future if that ever becomes a project of interest, but I think at this point in time that cart is miles beyond the proverbial horses.

I watched the video and wondered when/if you will leverage some of the more powerful D3 packages currently available?  I typically use ggplot for static plots, but more and more end up building D3 mockups, exporting the code, and then hacking away in D3 or JS.  Anyways, for exploring power data I'd find those much more useful than the R base plots.  Moreover, have you thought of using Packrat to build a GC plotting environment?  I don't start up R without also loading Dplyr, data.table, ggplot, and many other packages that would be incredibly useful for the basic plotting shown in the video.  Since R is almost always running in RStudio it's not an issue for me since the packages are already loaded, but should myself or someone else interface strictly through GC I guess it would be a tad bit tedious to load packages every time I would use this feature.  Also, filtering/munging in chains is typically in many ggplot calls, like this hypothetical scenario where I'd want a top chart that has a scatterplot of power by zone for a specific cadence and speed range, a bottom chart that has binned cadence ranges on the x axis and power on the y axis.  One could use such a chart from a race to see what cadence they self select at a certain pace.  With some of the dynamic options this could live on the same plot.

#Scatterplot for power by zone
1<- ggplot(ride_data%>%select(power, zone)%>%filter(date == '2016-05-27' & cadence >=80 & cadence <=100 & speed>=20)+
  geom_point(aes(x=zone, y=..count.., color=zone))+theme_bw()

#Scatterplot for power based on equally sized cadence bins from the data, provides precise bins compared to numeric increments
2<-ggplot(ride_data%>%select(power, cadence)%>%filter(date == '2016-05-27' & cadence >=80 & cadence <=100 & speed>=20)+
  geom_point(aes(x=(ride_data%>%summarize(bins=ntile(cadence))), y=power, color=bin)+theme_bw()

grid.arrange(1, 2, nrow=2)

This is just one specific example, but to do this I would need to load grid and gridExtra, ggplot, dplyr and its dependencies, and tidy.

Mark Liversedge

unread,
May 26, 2016, 6:26:05 PM5/26/16
to golden-cheetah-users, liver...@gmail.com


On Thursday, 26 May 2016 22:53:31 UTC+1, Karsten Walker wrote:
Neat stuff. I do most of my work in R as a living, but generally use RStudio as my IDE.  Given that I work a lot with machine learning and have access to high powered compute resources I am very curious as to performing some ML methods (clustering, nearest neighbor) on both rider and ride data in the future if that ever becomes a project of interest, but I think at this point in time that cart is miles beyond the proverbial horses.


ML is something I want to pursue. I would like to start collecting user data first though, which is still planned for v4.
We would use that data to train and develop generalized models.
 
I watched the video and wondered when/if you will leverage some of the more powerful D3 packages currently available?  I typically use ggplot for static plots, but more and more end up building D3 mockups, exporting the code, and then hacking away in D3 or JS.  

GC has its own graphics device, but that doesn't limit you to base graphics, ggplot2 etc work fine.
I would like to support rCharts etc via the builtin web engine, but that will be v4.1 I expect !
WRT interactive plotting I'm looking for advice since with respect, R is a bit of a mess in this regard.
 
Anyways, for exploring power data I'd find those much more useful than the R base plots.  Moreover, have you thought of using Packrat to build a GC plotting environment?  I don't start up R without also loading Dplyr, data.table, ggplot, and many other packages that would be incredibly useful for the basic plotting shown in the video.  Since R is almost always running in RStudio it's not an issue for me since the packages are already loaded, but should myself or someone else interface strictly through GC I guess it would be a tad bit tedious to load packages every time I would use this feature.  

You can pull in libraries in the R script that is associated with each chart.
Once loaded the library("...") methods does nothing, so its harmless to call multiple times.
 
Also, filtering/munging in chains is typically in many ggplot calls, like this hypothetical scenario where I'd want a top chart that has a scatterplot of power by zone for a specific cadence and speed range, a bottom chart that has binned cadence ranges on the x axis and power on the y axis.  One could use such a chart from a race to see what cadence they self select at a certain pace.  With some of the dynamic options this could live on the same plot.

This is where you have to consider you are running in GC.
You don't need to handle multiple charts in a single "page" .. you can have lots of charts and lots of pages...

CHEERS!

Mark

Karsten Walker

unread,
May 26, 2016, 8:22:01 PM5/26/16
to golden-cheetah-users, liver...@gmail.com
Perhaps I wasn't clear, but I don't want to have to manually use the library command in GC nor should a user necessarily have to.  I would suggest using Packrat to at least load a basic environment for the user in case they do not have another instance of R open and do not want to store redundant library commands in their scripts.  Or at least suggest using require() or library().  

Having 1 page per chart is IMO not a very robust UI. It would be great to be able to add a scrolling page function or option to return the charts as a flexdashboard or grob/grid object.  You lose the comparative power of plotting multiple metrics when you have to switch pages, kind of remember what the other one said, and repeat.

It depends which rCharts widgets you would like to use, but I find Plotly to be much easier for most things, but there are certain cases where writing rCharts syntax is really easy for people who are really used to chained commands and piping.  I use NVD3 and Morris sometimes, but later found that highchart and htmlwidgets did the same thing, but with less manipulation and code. You can simply just wrap a ggplot in (gg<-ggplotly()) to render it as a dynamic chart, so that's been my preference lately.  I've used all of the dynamic libraries extensively and their are really important nuances to data formatting for specific chart types.  This again goes back to my comment regarding packrat as any script that feeds into one of these plotting packages will usually require long format data as opposed to wide format, which is difficult (but not impossible) to wrap into a function.  

R is a bit of a mess in many regards and what typically happens is users end up taking chunks and pieces that they use often and create their own functions, packages, and environments.  For example, there is not a single function in any R package to adjust financial data to inflation, so I had to create function that returns a lookup table and also can take a data frame with dates and values and return a new inflation-adjustment column.  Something common, but it doesn't exist.  It's not something that needs its own package, but made its way into a package of things myself and co-workers do a lot and can save time and memory by loading a single package and its dependencies into the environment plus some of the underling C and SQL is optimized for the way we read in our data from various servers.

I digress, but I'm definitely willing to help provide some plotting guidance.  The standard these days for dynamic plotting is simply to use R for prototyping and then exporting the JS or JSON and doing the rest of the work in JS and D3 outside of R. Same as using Illustrator for polishing up static plots.  

If you're interested in collaboration on the ML side, contact me off list as I perform similar work daily in my formal/professional life.

Mark Liversedge

unread,
May 27, 2016, 5:22:32 AM5/27/16
to golden-cheetah-users, liver...@gmail.com
On Friday, 27 May 2016 01:22:01 UTC+1, Karsten Walker wrote:
Perhaps I wasn't clear, but I don't want to have to manually use the library command in GC nor should a user necessarily have to.  I would suggest using Packrat to at least load a basic environment for the user in case they do not have another instance of R open and do not want to store redundant library commands in their scripts.  Or at least suggest using require() or library().  

You are a fan of Packrat. Cool. This is a user choice.
We embed R into GC, it therefore inherits all the packages and setup from the base R install.

 

Having 1 page per chart is IMO not a very robust UI. It would be great to be able to add a scrolling page function or option to return the charts as a flexdashboard or grob/grid object.  You lose the comparative power of plotting multiple metrics when you have to switch pages, kind of remember what the other one said, and repeat.

One of the most important points here is R is embedded as an engine for GC, GC is not becoming Rstudio.
I'm sure there are many things we could do to the UX, but lets not conflate that with having R embedded.
 

It depends which rCharts widgets you would like to use, but I find Plotly to be much easier for most things, but there are certain cases where writing rCharts syntax is really easy for people who are really used to chained commands and piping.  I use NVD3 and Morris sometimes, but later found that highchart and htmlwidgets did the same thing, but with less manipulation and code. You can simply just wrap a ggplot in (gg<-ggplotly()) to render it as a dynamic chart, so that's been my preference lately.  I've used all of the dynamic libraries extensively and their are really important nuances to data formatting for specific chart types.  This again goes back to my comment regarding packrat as any script that feeds into one of these plotting packages will usually require long format data as opposed to wide format, which is difficult (but not impossible) to wrap into a function.  


I'm cautious about adopting any of the myriad of R approaches for charting using ggvis/plotly/JS/an.other framework/etc etc etc
I'd rather think about it for a while.
 
R is a bit of a mess in many regards and what typically happens is users end up taking chunks and pieces that they use often and create their own functions, packages, and environments.  For example, there is not a single function in any R package to adjust financial data to inflation, so I had to create function that returns a lookup table and also can take a data frame with dates and values and return a new inflation-adjustment column.  Something common, but it doesn't exist.  It's not something that needs its own package, but made its way into a package of things myself and co-workers do a lot and can save time and memory by loading a single package and its dependencies into the environment plus some of the underling C and SQL is optimized for the way we read in our data from various servers.


If there are functions that are useful for processing data within GC we can add them.
We could have an initialisation script sourced at startup.
 
I digress, but I'm definitely willing to help provide some plotting guidance.  The standard these days for dynamic plotting is simply to use R for prototyping and then exporting the JS or JSON and doing the rest of the work in JS and D3 outside of R. Same as using Illustrator for polishing up static plots.  


Cool thanks for the offer. Suggest you give it a whirl and see where it takes you.

 
If you're interested in collaboration on the ML side, contact me off list as I perform similar work daily in my formal/professional life.

Will do !

CHEERS

Mark 
Message has been deleted

Stefan

unread,
Jun 29, 2016, 5:31:43 AM6/29/16
to golden-cheetah-users
Perhaps someone can help here. In GC I do not get my R charts to show the y-axis label ("ylab"). Furthermore, bottom of tick mark labels is facing outwards. If I plot the the same data directly within R I get the standard behaviour? I use R x64 3.2.5

Here's one example, a boxplot L/R Balance vs. power zone. No y axis label showing and orientation of tick labels opposite to standard behaviour.



and the same when the means are plotted as scatter




Auto Generated Inline Image 1
Auto Generated Inline Image 2

Mark Liversedge

unread,
Jun 29, 2016, 7:22:13 AM6/29/16
to golden-cheetah-users
On Wednesday, 29 June 2016 10:31:43 UTC+1, Stefan wrote:
Perhaps someone can help here. In GC I do not get my R charts to show the y-axis label ("ylab"). Furthermore, bottom of tick mark labels is facing outwards. If I plot the the same data directly within R I get the standard behaviour? I use R x64 3.2.5


The margins probably need adjusting from the defaults to get the ylabs: par(mar=c(6,6,6,6))

The ticks are a problem that needs to be resolved; its about world co-ordinates for plotting having 0,0 as bottom left in R, but top left in QT.
If we apply a world transform text is displayed backwards (like looking in a mirror), so we manage it within the graphics device. But it needs to be improved. There are a few nits that are related to this, e.g. label placement on plots.

Mark

Stefan

unread,
Jun 29, 2016, 9:18:43 AM6/29/16
to golden-cheetah-users
yes, label placement is an issue:



I can specify "adj" but this does not really work either. Here with "adj=0.99), at adj=1 the label is not shown

Auto Generated Inline Image 1
Auto Generated Inline Image 2

Stefan

unread,
Jul 7, 2016, 12:35:57 PM7/7/16
to golden-cheetah-users
Another question: is it already possible to access the intervals of an activity via R? I can't find anything.

Mark Liversedge

unread,
Jul 7, 2016, 12:59:52 PM7/7/16
to golden-cheetah-users
On Thursday, 7 July 2016 17:35:57 UTC+1, Stefan wrote:
Another question: is it already possible to access the intervals of an activity via R? I can't find anything.

I need to add that. I'm not sure what the best way to do it is.
Just a list, with indexes to the first and last sample ?

interval name          type          start        stop
"Peak 1m"               Peak         1870      1830 
...

Mark

Stefan

unread,
Jul 7, 2016, 2:03:08 PM7/7/16
to golden-cheetah-users
This would be definitely the quickest solution. I assume giving access to all the interval metrics as stored in rideDB.json is significantly more work? This would not require having to recalculate all the metrics in the R code.

Stefan

JamesA

unread,
Oct 16, 2018, 11:13:14 AM10/16/18
to golden-cheetah-users
I'm hoping that this thread is still active, and kinda surprised that I haven't seen more comments about using RStudio etc. (is there a special topic section somewhere??)

I have R working in the current Development build v3.5-DEV1810 and have gotten ggplot working within GC, however wanted explore more refined plots in RStudio, but am having trouble getting activities to load correctly... I can load an activity, but get errors on the plots 

            > plot.ts(secs,watts,xy.lines=TRUE)
               Error in NCOL(x) : object 'secs' not found


When looking at the ride data there are lots of extraneous characters (in the following example I've stripped out the header lines), 


> ride
                        V1         V2            V3       V4
1              \t\t\t{ SECS:1       KM:0       WATTS:0    CAD:0
2              \t\t\t{ SECS:2   KM:0.002       WATTS:0    CAD:0
3              \t\t\t{ SECS:3   KM:0.002      WATTS:14   CAD:11
4              \t\t\t{ SECS:4   KM:0.004      WATTS:14   CAD:11
5              \t\t\t{ SECS:5   KM:0.004      WATTS:14   CAD:11
6              \t\t\t{ SECS:6   KM:0.008      WATTS:55   CAD:15
7              \t\t\t{ SECS:7   KM:0.012      WATTS:55   CAD:15
8              \t\t\t{ SECS:8   KM:0.014      WATTS:33   CAD:21


I've experimented with various R CSV load options to strip these characters, but don't have it right yet... I figured many here would have solved this issue... so is there an easy solution?



On Friday, May 27, 2016 at 5:22:32 AM UTC-4, Mark Liversedge wrote:
....
 
One of the most important points here is R is embedded as an engine for GC, GC is not becoming Rstudio.

.... 

CHEERS

Mark 
Reply all
Reply to author
Forward
0 new messages