Getting vectors from ggplot2

I am trying to show that in some of the data that I analyze (this relates to market share, there is a strange β€œblow." My code here is: -

qplot(Share, Rate, data = Dataset3, geom=c("point", "smooth")) 

(I appreciate that this is not very useful code without a data set).

In any case, can I get a number vector used to generate a smoothed string from R? I just need this layer to try to fit the model to smoothed data.

Any help gratefully received.

+4
source share
1 answer

Yes there is. ggplot uses the loess function as smoother by default in geom_smooth . this means that you can directly use loess to evaluate your anti-aliasing parameters.

Here is an example adapted from ?loess :

 qplot(speed, dist, data=cars, geom="smooth") 

enter image description here

Use loess to evaluate smoothed data and predict for estimates:

 cars.lo <- loess(dist ~ speed, cars) pc <- predict(cars.lo, data.frame(speed = seq(4, 25, 1)), se = TRUE) 

Now the ratings are in pc$fit and the standard error in pc$fit.se The next bit of code complements the set values ​​in data.frame, and then breaks it into ggplot :

 pc_df <- data.frame( x=4:25, fit=pc$fit) ggplot(pc_df, aes(x=x, y=fit)) + geom_line() 

enter image description here

+7
source

All Articles