tags:

views:

881

answers:

3

After some research I found the way to prevent an uninformative legend from displaying

... + opts(legend.position = "none")

Where can I find all the available "opts" for ggplot2?

A: 

How about the source code? It is not that the author hides it from you...

Plus, CRAN packages have to have documentation for all user-visible functions and their arguments so there is that too. But here I do agree that help(opts) does not get you very far.

Dirk Eddelbuettel
Thank you. How can I see the source code?. I tried ggplot2::opts but probably it was not what you meant..
gd047
Go to CRAN and _download_ the source code.
Dirk Eddelbuettel
I don't know if the "Use the Source Luke" approach is the best way to go on this one-- opts() basically returns a subclassed list() object. To figure out how this object affects the output of ggplot2 involves digging deeper into the source code. That in turn would involve coming to terms with S3 and operator overloading, Lattice, and the Proto object framework-- to name a few. Certainly reasonable for a developer asking "how is opts() implemented?" but not for a user seeking to understand "how does opts() affect the graph I am making?"
Sharpie
You are making it way too complicated. As discussed, `help(opts)` is close to useless. My next step then is to `grep` through the sources to see which values of `opts()` are actually used and where. That's all.
Dirk Eddelbuettel
That works well if you have a list of values to grep for. In this case, the question was "what are the valid values for opts?". `opts()` takes `...` as it's only argument-- the actual implementation of key/value pairs is scattered deeper in the source code.
Sharpie
It didn't say grep for values of opts, I said grep for opts -- which allows me to find out which values are read from it, and see in which contents.
Dirk Eddelbuettel
I understood that-- I think what I'm trying to say is that after spending some time deconstructing the source code myself, I feel this approach is not as straight forward as it is with other packages due to the complexity of the ggplot2 implementation. I don't get much by searching for `opts`-- the first step is pieces of code which execute on objects of class `options` which get rolled into objects of class `ggplot` which get... it's a very intricate system.
Sharpie
+2  A: 

All the options I've ever used have been explained in hadley's great ggplot2 book.

Jonathan Chang
+3  A: 

The ggplot2 package does not contain much reference information-- this is probably because Hadley has put a lot of work into developing and polishing the package, creating a website full of examples and writing an excellent book that describes the system in detail.

The first place I would look for answers would be the ggplot2 website:

http://had.co.nz/ggplot2/

However, since opts() is not really a geom, stat or scale there are no examples that focus specifically on it. The next place to look would be the section of the website that contains material from the book-- including source code for examples:

http://had.co.nz/ggplot2/book/

The example code for the chapter "Polishing your plots for publication" contains some well commented examples of using set_theme() and opts() to alter plot appearance.

The ultimate source for information is of course the book it's self. If you find ggplot2 has simplified and streamlined your workflow for producing statistical graphics, buying a copy of the book is a great way to say "thank you" and support the further development of the package.

Update

After some further investigation, you may be able to find a relatively complete list of options by listing out the source of one of the "theme" functions such as theme_bw. The source doesn't provide a description of the possible key=value pairs, but it does at least show most of the key names that have an effect when set via opts().

Sharpie
Thanks a lot. I was expecting to find something like this (but for ggplot2 of course) http://finzi.psych.upenn.edu/R/library/ggplot/html/build-options-8a.html
gd047
Hmm, a list of options (complete?) is also included on page 39 here http://had.co.nz/ggplot2/book.pdf
gd047
That table describes most of the options-- the master list seems to be table 8.1 in the full book.
Sharpie