TheHall
TheHall

Reputation: 1

R not plotting, says Unknown parameter: method (ggplot2)

I have just installed ggplot2 and was testing out some of its functionality and have come across this error which doesn't allow it to plot because of the method argument. I am running R version 3.2.3 on Mac & have the most up to date ggplot2; below is my code. Any advice how to fix this?

library(ggplot2)
str(diamonds)
qplot(carat, price, data=diamonds, log='xy', 
     geom=c('point','smooth'), method='lm')

Upvotes: 0

Views: 1808

Answers (2)

Kumar Manglam
Kumar Manglam

Reputation: 2832

qplot now is basically a ggplot decomposed. You can easily extend qplot and add whatever you want inside it. qplot now is more inline with basic plot() in R. As far as your question is concerned, you can add geom_smooth(method="lm") in your qplot as:

qplot(carat, price, data=diamonds, log="xy", 
     geom=c('point')) + geom_smooth(method="lm")

For details you can look into the code of qplot using edit(qplot). Hope this helps.

Upvotes: 1

Ben Bolker
Ben Bolker

Reputation: 226162

I don't know how to do it with qplot() (it may not be possible) but you can do it with the full ggplot() command:

library(ggplot2) 
ggplot(diamonds,aes(carat,price))+
   scale_x_log10() + scale_y_log10() +
   geom_point()+
   geom_smooth(method="lm")

Upvotes: 3

Related Questions