Possible Duplicate:
how to define fill colours in ggplot histogram?
I want to plot (histogram) counts of fishes per length class from a data frame which summarize this information in a binned format (data.frame(…,length=length, counts=N)). I’m a new user of ggplot2, but seems It could be a good choice. Can I create this histogram from a data.frame object?
Sorry for being so brief, Here is the structure of a piece of df,
'data.frame': 416 obs. of 3 variables:
$ specie: Factor w/ 1 level "speciesA": 1 1 1 1 1 1 1 1 1 1 ...
$ length: num 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 ...
$ Counts: num 2 0 0 0 1 0 1 1 0 1 ...
In this case, fishers catch 2 individuals 34.5 cm large, 1 36.5, and so on…
Thank you very much for your answers
Since you did not provide a sample of your data, I have created data per your description.
Length of fishes from 34.5 to 49.5 (arbitrary units: a.u.). Min length of fishes was 34.5 and Max length of fishes was 49.5
Number of fishes having a specific length starts at 0 and ends at 2.
Create a sample of counts having the length of x
Create a dataframe1 that includes length and counts. Notice: The structure of df1 satisfies the data structure per your description
Since you already counted the number of fishes having a specific length, you have to convert it back to the original format, i.e., if 2 fishes having 34.5(a.u), it should be converted back to two 34.5s.
Plot the data using ggplot function. Notice there are many ways to do the same plot. You may try geom_histogram to get the same plot as well.
Check this site for more info
Hope this helps!