ggplot2 - Plotting many natural cubic splines in ggplot (R) -


forgive me if i'm asking basic question here (i'm not experienced in r), i'm trying plot natural cubic splines in r , i'm running against wall.

i have data set has ~3500 rows , 30 columns. data set of single-season baseball statistics 270 different baseball players on entire careers. basically, have 270 time series (one each player).

i'm interested in player performance measured thing called woba on time, want fit natural cubic spline each , overlay splines on 1 graph. , yes, must natural cubic spline. , far know, way in ggplot.

my current code doing is:

  #initialize plot   plot <- ggplot(data, aes(x=age, y=woba, color=playerid, group=playerid)) + theme(legend.position="none")    #loop through players add splines   (i in unique(data$playerid)) {     plot <- plot + stat_smooth(method = lm, formula = y~ns(x,3), data=data[which(data$playerid=="i"),list(playerid,age,woba)], se=false) } 

i have checked can run code snippet inside loop manually couple of different players, , plot turns out want it. when try run loop, takes forever. checked memory usage loop running , ran out (i on 4gb machine).

i'm little confused why is. not have expected fitting 270 splines cause r use >2gb free memory @ time of execution.

i'm new r, i'm sure i'm missing something. can give pointers? sorry if bone-headed question!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -