green hand looking for help

25 views
Skip to first unread message

linl...@gmail.com

unread,
May 10, 2016, 11:38:36 AM5/10/16
to ggplot2
Hello,

I'm now learning ggplot2, and when I used qplot(), the computer told me that parameter span, method, formula can not be found.

I just followed the book ggplot2 exactly, so I have no idea what's wrong...

Could you help me? Thanks a lot !

John Rauser

unread,
May 10, 2016, 4:36:22 PM5/10/16
to linl...@gmail.com, ggplot2
Can you give us the exact command you entered along with the verbatim error message?  Then we might be able to help.  ggplot2 has changed somewhat since the book was published, so it may be that some of the examples in the book no longer work.

-J

--
--
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.
For more options, visit https://groups.google.com/d/optout.

Dennis Murphy

unread,
May 10, 2016, 7:17:50 PM5/10/16
to linl...@gmail.com, ggplot2
Hi:

ggplot2 is now at version 2.1.0 on CRAN, and Hadley is in the process
of writing an update to the book, anticipated to be published later
this year AFAIK. The 2009 book is now obsolete in several significant
ways, notably the theming system and some new/improved features in
facet_wrap() and facet_grid() added in version 2.0.0. Much in ggplot2
has changed since the book was published in 2009. If you want to get a
glimpse of the new version, Google 'github ggplot2-book'.

Note that qplot() has been deemphasized in the new book, to the point
where it isn't even mentioned except for a link citation to the first
edition on the ggplot2.org page, which I suspect you've already found.
It's in your best interest to learn ggplot() instead of qplot(); it
has a higher learning curve at first, but it has far more potential
for creativity than does qplot() and is more consistent and flexible
in terms of its syntax. Even in the original book, Hadley noted that
qplot() was supposed to be a way to transition from base graphics to
ggplot2 graphics; in other words, qplot() is ggplot() on training
wheels. (This is a biased opinion, as I made a point of avoiding
qplot() from the time I started learning ggplot2 several years ago.)

As for the code that threw the error you mentioned, the arguments
mentioned in the error message sound like they come from loess(),
which means you probably tried to use geom_smooth() somewhere in your
code, probably as a second argument to geom = in qplot(). A similar
problem was posted to this list a few months ago. Don't do this; use
ggplot() instead. qplot() behaves unpredictably at times when you pass
more than one geom in a single qplot() call, especially if you are
trying to pass arguments to one of the geoms but not the other. Here
is a short reproducible example to illustrate the problem and a couple
of workarounds:

library(ggplot2)
# Works
qplot(disp, mpg, data = mtcars, geom = c("point", "smooth"))
# Throws an error
qplot(disp, mpg, data = mtcars, geom = c("point", "smooth"), span = 0.5)

# qplot workaround
qplot(disp, mpg, data = mtcars, geom = "point") +
geom_smooth(span = 0.5)

# ggplot() equivalent
ggplot(mtcars, aes(x = disp, y = mpg)) + # base layer
geom_point() + # points layer
geom_smooth(span = 0.5) # smoothing layer

As the other reply mentioned, if you had provided a minimal
reproducible example, one might be better positioned to help you solve
your immediate problem. See the link at the bottom of this message for
further details of how one might do that.


Dennis

On Tue, May 10, 2016 at 8:14 AM, <linl...@gmail.com> wrote:

linl...@gmail.com

unread,
May 11, 2016, 6:32:52 AM5/11/16
to ggplot2, linl...@gmail.com
Hi John,

Thanks for your help !

Since I can not open the link here, I might as well copy them here. The commands I've tried according to the book are:

qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
      span = 1)

qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
      method = "gam", formula = y ~ s(x))

And today I also found the following one did not work.

qplot(displ, hwy, data=mpg, colour=factor(cyl), geom="line") + 
  opts(drop = "legend_box")

But according to your response, I get to know the reason and I think I'd better skip the qplot() part.

Thanks,
Claire

在 2016年5月11日星期三 UTC+8上午4:36:22,John Rauser写道:

linl...@gmail.com

unread,
May 11, 2016, 7:08:56 AM5/11/16
to ggplot2, linl...@gmail.com
Hi Dennis,

Thanks for your suggestion and information !!

I do think I should follow you and skip learning qplot for I met another propblem today. And I'm looking forward to the new version.

Thanks,
Claire



在 2016年5月11日星期三 UTC+8上午7:17:50,Dennis Murphy写道:

Hadley Wickham

unread,
May 11, 2016, 8:44:29 AM5/11/16
to Dennis Murphy, linl...@gmail.com, ggplot2
FWIW the book has been done for >6 months now, but Springer is taking
forever to actually publish it :(

Hadley
--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages