Let's reproduce the example we are working with:
chol <- read.table(url("http://assets.datacamp.com/blog_assets/chol.txt"), header = TRUE)
We are now representing two ggplot histograms:
library(ggplot2)
plot1 <- ggplot(data=chol, aes(chol$AGE)) +
geom_histogram(breaks=seq(20, 50, by = 2),
col="red",
fill="green",
alpha = .2) +
labs(title="Histogram for Age") +
labs(x="Age", y="Count") +
xlim(c(18,52)) +
ylim(c(0,100))
plot2 <- ggplot(data=chol, aes(WEIGHT)) +
geom_histogram() +
labs(title="Histogram for Weigth") +
labs(x="Weigth", y="Count") +
ylim(0,50)
These are the two histogramas, first plot1
and second plot2
.
I would like to merge both of them, representing plot1
in the X axis, and plot2
in the Y axis of the new plot. The result might be similar to this:
How can I achieve this goal?