I registered here specifically for this purpose.
Basically I have two data frames that have the exact same information but from two different years.
Here the head() of one of the data frames:
species dbh_cm height_m f plot dbh_m ba
1 1 0.7 1.34 7.1627066 16 0.007 3.848451e-05
2 3 1.9 1.95 2.0018036 16 0.019 2.835287e-04
3 3 4.0 3.05 0.9120516 16 0.040 1.256637e-03
4 1 3.5 2.27 1.0072122 16 0.035 9.621128e-04
5 3 0.6 1.52 6.9312671 16 0.006 2.827433e-05
6 3 4.2 2.70 0.9406631 16 0.042 1.385442e-03
volume class Sp
1 0.0003693754 (0,5] Spruce
2 0.0011067593 (0,5] Larch
3 0.0034956596 (0,5] Larch
4 0.0021997474 (0,5] Spruce
5 0.0002978850 (0,5] Larch
6 0.0035187332 (0,5] Larch
For plotting the graphs for each of these I used:
ggplot(data=trees_b, aes(x=class, fill = Sp)) +
geom_bar(stat = "count") +
labs( x = "DBH classes [cm]", y = "Number of trees [n]", fill="Species") +
scale_x_discrete(labels=c("(0,5]" = "2.5","(5,10]" = "7.5", "(10,15]" = "12.5",
"(15,20]" = "17.5", "(20,25]" = "22.5", "(25,30]" = "27.5",
"(30,35]" = "32.5", "(35,40]" = "37.5", "(40,45]" = "42.5",
"(45,50]" = "47.5", "(50,55]" = "52.5", "(55,60]" = "57.5",
"(60,65]" = "62.5", "(65,70]" = "67.5","(70,75]" = "72.5",
"(75,80]" = "77.5", "(80,85]" = "82.5")) +
scale_fill_viridis(direction = -1, discrete = T) +
theme(axis.text.x = element_text( size = 15),
axis.text.y = element_text (size = 15),
axis.title = element_text(size = 15),
legend.text = element_text (size = 15),
legend.title = element_text (size = 16, face = "bold"))
I know the code is not the cleanest but it worked out perfectly for what I needed and that is this:
Now I want to basically combine the two graphs into one for comparison purposes, is there a way to do that?