Is it possible to combine two plots and make it one plot?
These are the plots I am trying to combine. I have tried the "combined_plot" command, but I get the same result - two separate plots.
Here are my codes:
Plot 1:
plot1 <- ggplot() +
geom_bar(data = complete_august_data, aes(x = DATE, y = Count, fill = MANUAL.ID.),
stat = "identity", width = 0.7, position = "dodge") +
geom_bar(data = complete_july_data, aes(x = DATE, y = Count, fill = MANUAL.ID.),
stat = "identity", width = 0.7, position = "dodge") +
labs(title = "Kumulative kurver for juli og august ved Borupgård 2018",
x = "Dato",
y = "Kumulative observationer",
fill = "Art") +
scale_x_date(date_labels = "%Y-%m-%d") +
theme_minimal()
Plot 2:
plot2 <- ggplot(result_df, aes(x = Dato, y = Belysning)) +
geom_line(color = "gold2") + # Tilføj en linje
geom_point(color = "goldenrod", size = 2) + # Tilføj punkter
labs(x = "Dato", y = "Belysning", title = "Graf over belysning 25 juli - 29 august 2018") +
scale_x_date(limits = as.Date(c("2018-07-26", "2018-08-29")),
date_breaks = "5 day",
date_labels = "%Y-%m-%d")+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme_bw()
](https://i.stack.imgur.com/9D7ma.png)
If you want a single plot with two y-axes, it's possible with ggplo2 but requires a bit of fiddling.
Here, I'm taking the first axis to go up to 6000. I would recommend manually setting the first y-axis-limit so the two are 100% congruent.
Note, they're plotted relative to y-axis 1, so you need to rescale them.
I tried simplifying by merging all three datasets into one. If that causes issues just add them in singularly like you were doing. But I created a sample dataset to look like yours and it gives me this: