qplot() Error: Unknown parameters: span

171 views
Skip to first unread message

Benny Guo

unread,
Aug 19, 2016, 7:12:46 AM8/19/16
to ggplot2
I use the example code in ggplot2. Elegant Graphics for Data Analysis to plot . I encounter the error message below:
> qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 1)
Error: Unknown parameters: span
my ggplot2 version is 2.1.0


who can tell me what happens? 

Brandon Hurr

unread,
Aug 19, 2016, 4:37:34 PM8/19/16
to Benny Guo, ggplot2
My guess is that you're using the old book, because I can't find this in the second edition. 

In my experience, qplot() was very useful in the beginning, but it made me lazy and made learning the full ggplot2 syntax more difficult. Also, I believe that qplot was semi-recently altered to simplify its capabilities. This might explain why your line of code no longer works. 

I don't have the dsmall code from the book in front of me so I don't know how big dsmall is compared to diamonds, but with the full diamonds dataset you are over 1000 rows of data so the default will be gam instead of loess. gam does not accept the span argument so you can give it different numbers all day and it will ignore you. 


These pages will give you some background. 

If you insist on using qplot(), just take the span=1 argument out of qplot and put it in stat_smooth() like so:
qplot(carat, price, data = dsmall, geom = c("point", "smooth")) + stat_smooth(span=1)

HTH,
B

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dennis Murphy

unread,
Aug 19, 2016, 11:30:23 PM8/19/16
to Benny Guo, ggplot2
Hi::

This has come up before, and is a good example of why you should be
using ggplot() instead of qplot(). F The issue is that you've called
two geoms in your qplot() call, so qplot() doesn't really "know" that
span is supposed to apply to geom_smooth() rather than geom_point().
This problem disappears when you use

ggplot(dsmall, aes(x = carat, y = price)) +
geom_point() +
geom_smooth(span = 1)

or alternatively, if you insist on using qplot(),

qplot(carat, price, data = dsmall, geom = "point") + geom_smooth(span = 1)

To address Brandon's question, dsmall is a random subsample from the
diamonds data, of length 1000 IIRC.

Dennis

On Thu, Aug 18, 2016 at 7:43 PM, Benny Guo <baili...@gmail.com> wrote:
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.

Benny Guo

unread,
Aug 21, 2016, 9:43:39 PM8/21/16
to ggplot2, baili...@gmail.com
Dear Brandon Hurr, thanks for your reply. I just begin to learn ggplot2, and start from qplot temporally 

在 2016年8月20日星期六 UTC+8上午4:37:34,Brandon Hurr写道:
My guess is that you're using the old book, because I can't find this in the second edition. 

In my experience, qplot() was very useful in the beginning, but it made me lazy and made learning the full ggplot2 syntax more difficult. Also, I believe that qplot was semi-recently altered to simplify its capabilities. This might explain why your line of code no longer works. 

I don't have the dsmall code from the book in front of me so I don't know how big dsmall is compared to diamonds, but with the full diamonds dataset you are over 1000 rows of data so the default will be gam instead of loess. gam does not accept the span argument so you can give it different numbers all day and it will ignore you. 


These pages will give you some background. 

If you insist on using qplot(), just take the span=1 argument out of qplot and put it in stat_smooth() like so:
qplot(carat, price, data = dsmall, geom = c("point", "smooth")) + stat_smooth(span=1)

HTH,
B
On Thu, Aug 18, 2016 at 7:43 PM, Benny Guo <baili...@gmail.com> wrote:
I use the example code in ggplot2. Elegant Graphics for Data Analysis to plot . I encounter the error message below:
> qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 1)
Error: Unknown parameters: span
my ggplot2 version is 2.1.0


who can tell me what happens? 

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.

Benny Guo

unread,
Aug 21, 2016, 9:47:45 PM8/21/16
to ggplot2, baili...@gmail.com
Thanks for your reply,I learn it.

在 2016年8月20日星期六 UTC+8上午11:30:23,Dennis Murphy写道:

f2017...@umt.edu.pk

unread,
Feb 6, 2018, 1:28:35 PM2/6/18
to ggplot2
HI,

Any one of you can share the latest "ggplot2. Elegant Graphics for Data Analysis " pdf book.

Regards,
Umer Saeed

Brandon Hurr

unread,
Feb 6, 2018, 1:32:03 PM2/6/18
to f2017...@umt.edu.pk, ggplot2
My suggestion would be to look at the R for Data Science book online as a starting point.

http://r4ds.had.co.nz/

There is a section on data visualization that uses ggplot2 that could get you started.

http://r4ds.had.co.nz/data-visualisation.html

It's online and free.

HTH,
B

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages