[R] Create histogram from data matrix

hadley wickham h.wickham at gmail.com
Sat Apr 18 17:50:10 CEST 2009


On Fri, Apr 17, 2009 at 2:07 PM, Paul Warren Simonin
<Paul.Simonin at uvm.edu> wrote:
> Thank you all for your advice.
>  I have received some good tips, but it was suggested I write back with a
> small simulated data set to better illustrate my needs. So, currently my
> data frame looks something like:
>
> ID (date)  Temperature  Number of fish
> 200706183       5       456
> 200706183       5       765
> 200706183       4       567
> 200706183       3       876
> 200706183       3       888
> 200706183       2       111
> 200706184       8       2345
> 200706184       8       654
> 200706184       8       7786
> 200706184       7       345
> 200706184       6       234
> 200706184       6       123
>
>
> I need to create a plots for each ID (date) of the number of fish observed
> at each temperature. Obviously my data frame is much larger. These plots do
> not have to be in a specific histogram format, but it seems this may be
> appropriate.
> Thanks for any additional advice as to how this may be done, either using
> plot commands or reformatting my data.
>
> It seemed the ggplot2 options may be good but so far I have tried qplot with
> no success:
>
> my most recent code looks like:
>
> qplot(temp,number of fish, geom="histogram",binwidth=1)
>
> I have tried various tweaks of this, but no success.

The problem is number of fish is not a valid R variable name because
it has spaces in it (and you didn't specify the data frame to look for
those variable in).

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list