Hi,
I am trying to create a piecewise geom_smooth, that is, I am trying to create difference geom_smooth curve for different portions for my x-axis.
Using the following code:
y = floor(runif(100,1,10))
df = as.data.frame(cbind(x,y))
p <- p + geom_line(aes(group = 1))
p <- p + geom_smooth(aes(df$x,df$y,group = 1, data = subset(df, x>90), fullrange = FALSE))
I want to create a geom_smooth curve only for the portion that is for x > 90 (ideally, i would like one for each of x<30, one for 31<x<50, etc).
I have tried various combinations, but I don't seem to know what is wrong as it does not work. I still want to have a geom_line for the whole x-series, but want different geom_smooths overlayed.
I get errors such as "Error: Aesthetics must either be length one, or the same length as the dataProblems:subset(df, x > 90)", "ggplot2 doesn't know how to deal with data of class uneval", "arguments imply differing number of rows" for different orderings of arguments.
Help would be greatly appreciated,
Thank you,
Dhaval