Working from the following dataframe:
> foo
species density day percent
1 species1 high 1 0.40
2 species1 low 1 0.20
3 species1 medium 1 0.40
4 species2 high 1 0.35
5 species2 low 1 0.10
6 species2 medium 1 0.55
7 species3 high 1 0.35
8 species3 low 1 0.20
9 species3 medium 1 0.45
10 species4 high 1 0.30
11 species4 low 1 0.20
12 species4 medium 1 0.50
13 species1 high 100 0.50
14 species1 low 100 0.40
15 species1 medium 100 0.10
16 species2 high 100 0.40
17 species2 low 100 0.05
18 species2 medium 100 0.55
19 species3 high 100 0.65
20 species3 low 100 0.05
21 species3 medium 100 0.30
22 species4 high 100 0.40
23 species4 low 100 0.20
24 species4 medium 100 0.40
I have created the following faceted bar graph:
require(ggplot2)
foo$density<-factor(foo$density,levels=c('low','medium','high'))
d <- ggplot(foo, aes(x=species, y=percent, fill=density)) +
geom_bar(aes(width=.65), stat="identity") +
facet_grid(. ~ day)
However, I would like to merge these graphs to create a single two-factor bar graph. On the x-axis, each day- 1 and 100 - would be grouped by species. Any suggestions on how to create this?
Many thanks!
A double bar graph is a graphical display of information using two bars besides each other at various heights. The bars can be arranged vertically or horizontally. We can use a double bar graph to compare two data groups. A double bar graph has two axes.
Try this one
foo$species_day <- with(data = foo, expr = paste(species, day))
d <-ggplot(foo, aes(x=species_day, y=percent, fill=density)) +
geom_bar(aes(width=.65), stat="identity")
You can rearrange the levels if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With