I have created some plots using ggplot2
in R. Now, I want to combine two plots using grid.arrange
, however after I use this function I get only empty plots.
I also tried cowplot
library but I am getting same problem.
## Pipe age distribution in the initial pipe network conditions
pipe_age_0 = 2019 + net.ini$time.construction
pipe_age = 2019 - pipe_age_0
p6 <- ggplot(net.ini, aes(x = pipe_age))
p6 + geom_histogram(binwidth = 1,
col="black",
size=0.1,
fill = "lightgrey") +
scale_x_continuous(breaks = seq(from = 0, to = 140, by = 10)) +
labs(y="Count", x="Age [Years]") +
theme_bw(base_size = 12, base_family = "")
## Density stacked with histogram count
p7 <- ggplot(net.ini, aes(x = pipe_age))
p7 + geom_histogram(aes(y = ..density..),
binwidth = 1,
col="black",
size=0.1,
fill = "lightgrey") +
geom_density(alpha = 0.1, fill="#FF6666") +
scale_x_continuous(breaks = seq(from = 0, to = 140, by = 10)) +
labs(y="Density", x="Age [Years]") +
theme_bw(base_size = 12, base_family = "")
grid.arrange(p6, p7)
I expect to have two graphs one above another, or one beside another using grid.arrange
. However for some reason I keep getting empty plot. This is how plots p6 and p7 look like, and third one with grid.arrange
, the empty plot: