I have the following code:
library("ggplot2")
x1 = as.numeric(x=QualidadeARO3$Ilhavo)
x2 = as.numeric(x=QualidadeARO3$VNTelha_Maia)
ggplot (QualidadeARO3, aes(x=x1, color="Ílhavo")) +
geom_histogram(fill="black", position="dodge", alpha = 0.2) +
theme(legend.position="top") +
xlab("microgramas por metro cúbico") +
ylab("horas")
ggplot(QualidadeARO3, aes(x=x2, color="VN Telha-Maia")) +
geom_histogram(fill="blue", position="dodge", alpha = 0.2)+
theme(legend.position="top") +
xlab("microgramas por metro cúbico") +
ylab("horas")
Where QualidadeARO3
is a data sheet imported from Excel that looks like this:
And
ggplot (QualidadeARO3, aes(x=x1, color="Ílhavo")) +
geom_histogram(fill="black", position="dodge", alpha = 0.2) +
theme(legend.position="top") +
xlab("microgramas por metro cúbico") +
ylab("horas")
and
ggplot(QualidadeARO3, aes(x=x2, color="VN Telha-Maia")) +
geom_histogram(fill="blue", position="dodge", alpha = 0.2)+
theme(legend.position="top") +
xlab("microgramas por metro cúbico") +
ylab("horas")
This is good and all so far, but my problem is that both graphs "run" independently, i.e., when I call the second ggplot
the first graph disappears, when I want to overlap both into a single histogram, as well as both color labels.
I have seen Overlaying histograms with ggplot2 in R , but still no clue. Any help?