First of all, this thread has been moved here from R-help at my
suggestion. The context is contained inline.
On Wed, Aug 17, 2011 at 1:22 AM, Johannes Radinger <JRad...@gmx.at> wrote:
> Hello Dennis,
>
>> Hi:
>>
>> On Tue, Aug 16, 2011 at 5:48 AM, Johannes Radinger <JRad...@gmx.at>
>> wrote:
>> > Hello,
>> >
>> > I am a beginner with ggplot and after doing simple graphs (histogram,
>> segments etc.)
>> > some questions came up:
>> >
>> > 1) I tried to do a histogram, but nothing is displayed although it works
>> with another vector.
>> > I think it is because of the very small values (n=1000, min=1.222e-24
>> max, 1.890e-20).
>> > I used qplot(variable,geom="histogram")... If do it with the standard
>> plot function it works perfectly.
>>
>> Similar problems have been reported before, but I thought it had been
>> fixed in recent versions. [I could be wrong, though...) Which versions
>> of R and ggplot2 are you using? (Report sessionInfo(), please.)
>
> Here the output from sessionInfo:
>
> R version 2.13.1 (2011-07-08)
> Platform: i386-apple-darwin9.8.0/i386 (32-bit)
> locale:
> [1] de_AT.UTF-8/de_AT.UTF-8/C/C/de_AT.UTF-8/de_AT.UTF-8
> attached base packages:
> [1] grid stats graphics grDevices utils datasets
> methods base
> other attached packages:
> [1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.6
> loaded via a namespace (and not attached):
> [1] tools_2.13.1
>
> It should be the most recent version...
> Is there anything I can do that also the histograms with very small
> values are displayed?
I'll let Hadley address that question, because I thought it was a
corrected bug, but as I mentioned in my earlier reply, I could be
wrong.
>
>
>
>
>> >
>> > 2) I want to use scale_colour_gradient(). Is there any reference where I
>> can
>> > find the predefined colour-palletes like rainbow etc. and how they look
>> like?
>>
>> There is some discussion of this in Hadley's ggplot2 book (pp.
>> 104-106). See also
>> http://had.co.nz/ggplot2/scale_gradientn.html
>> http://had.co.nz/ggplot2/scale_brewer.html
>
> Thank you very much, but I don't have Hadley's book (yet). And sadly
> on the mentioned website are only some examples given. I am just
> looking for a summary where most of the available standard pallettes
> are mentioned and shown...
If you look at the scale_brewer help page and look carefully at the
palette item, you'll see a snippet of code that you can copy and paste
into your R session that will return the various ColorBrewer palettes
available in R. Note that the ColorBrewer palettes are for use with
discrete scales with a limited number of levels (max 7-9 depending on
the palette). Other color palettes can be made available through the
colorRamp() and colorRampPalette() functions from the grDevices
package (autoloaded), the colorspace package, the vcd package, the
munsell package and undoubtedly several other packages with similar
capabilities. Hadley's book shows an example where color palettes are
created from functions in the vcd package (which in turn uses the
colorspace package) and then transported to ggplot2. The code is
available on the book website in the chapter titled 'Scales, axes and
legends'. [http://had.co.nz/ggplot2/book/scales.r ] Look for a
commented paragraph that starts with 'Gradient color scales'; the code
beneath it shows how to write a function to create a palette that you
can pass into a ggplot call, with a couple of illustrative examples.
The point of this long-winded response is that the set of potential
palettes one can use is more or less up to you, because there are many
possibilities available. There are a few papers/talks available
on-line about the use of color in R, and the vast majority of it
should be transportable to ggplot2.
HTH,
Dennis
>
>
>>
>> >
>> > 3) How can I change the white grid in the background? In some cases I'd
>> like to
>> > remove the white grid
>>
>> A group of enterprising ggplot2 users recently put together a page of
>> user-defined themes for the community:
>> https://github.com/hadley/ggplot2/wiki/themes/
>>
>> Another one, called 'theme_nothing' and authored by David Kahle of
>> Rice U., blanks out most of the options in a ggplot:
>>
>> # david kahle
>> # sept 27, 2010
>>
>> theme_nothing <- function (base_size = 12){
>> structure(list(
>> axis.line = theme_blank(),
>> axis.text.x = theme_blank(),
>> axis.text.y = theme_blank(),
>> axis.ticks = theme_blank(),
>> axis.title.x = theme_blank(),
>> axis.title.y = theme_blank(),
>> axis.ticks.length = unit(0, "lines"),
>> axis.ticks.margin = unit(0, "lines"),
>> legend.position = "none",
>> panel.background = theme_blank(),
>> panel.border = theme_blank(),
>> panel.grid.major = theme_blank(),
>> panel.grid.minor = theme_blank(),
>> panel.margin = unit(0, "lines"),
>> plot.background = theme_blank(),
>> plot.title = theme_text(size = base_size * 1.2),
>> plot.margin = unit(c(-1, -1, -1.5, -1.5), "lines")),
>> class = "options")
>> }
>>
>> You could study these themes to get an idea how to create one of your
>> own that retains the features you desire.
>
> Thank you very much, that was really helpful. I'll try that!
>
>
>> >
>> > 4) How are the ticks on the X-axis calculated? Can they be changed in a
>> way that
>> > always 5 ticks with the corresponding numbers (labels) are displayed on
>> the X-axis.
>>
>> Yes; see http://had.co.nz/ggplot2/scale_continuous.html and note the
>> examples.
>
> Thank you, I'll check that!
>
>>
>> There is also a list for ggplot2 apart from R-help; you can subscribe to
>> it from
>> http://had.co.nz/ggplot2/
>>
>> Look for the heading 'Mailing list'; the on-line help pages are
>> further down the page.
>>
>> Follow-ups should probably be sent to this list rather than R-help.
>>
>> HTH,
>> Dennis
>> >
>> > Thank you very much
>> >
>> > Johannes
>> > --
>> >
>> > ______________________________________________
>> > R-h...@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>
It's corrected in the current development version.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/