[R] ggplot - some questions concerning histograms

Dennis Murphy djmuser at gmail.com
Tue Aug 16 19:21:23 CEST 2011


Hi:

On Tue, Aug 16, 2011 at 5:48 AM, Johannes Radinger <JRadinger at 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.)
>
> 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

>
> 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.
>
> 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.

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-help at 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.
>



More information about the R-help mailing list