Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'method' parameter doesn't exist in qplot in R?

Tags:

r

ggplot2

The documentation for qplot doesn't contain the 'method' parameter. The error I get is -

> qplot(displ, hwy, data = mpg, geom=c("point", "smooth"),facets=.~drv,method="loess")
Error: Unknown parameters: method

My version of R is 3.2.1 and ggplot2 version is 2.0.0, if it helps.

like image 813
Mihir Sawant Avatar asked Dec 20 '15 08:12

Mihir Sawant


2 Answers

Welcome to SO. You're getting the error because of the update in ggplot2; the tutorial that you're looking at was probably from an older version. You will see that at a lot of places on the internet.

For reference: On this forum, one generally posts the objective of the exercise, the exact (or minimum working example) code and output and states the efforts made at the stage where stuck. This helps the other members give a more coherent answer.

like image 195
skoh Avatar answered Oct 04 '22 14:10

skoh


No need for method as geom_smooth() assumes loess

qplot(displ, hwy, data = mpg, geom=c("point", "smooth"),facets=.~drv)

If geom="smooth", a loess fit line and confidence limits are added by default. When the number of observations is greater than 1,000, a more efficient smoothing algorithm is employed. Methods include "lm" for regression, "gam" for generalized additive models, and "rlm" for robust regression. The formula parameter gives the form of the fit.

enter image description here

like image 40
Vedda Avatar answered Oct 04 '22 14:10

Vedda