Korzystanie ggplot i siatki pakiet.
library(gridExtra)
library(ggplot2)
library(grid)
p1 = ggplot(aes(x = mpg), data = mtcars) +
geom_histogram(fill = "lightblue", color = "black",binwidth = 1) +
scale_x_continuous(limits = c((min(mtcars$mpg)),(max(mtcars$mpg))),
breaks = pretty(mtcars$mpg, n = 10)) +
labs(x = "", y = "Count", title = ("Histogram & Boxplot of mpg"))
p2 = ggplot(aes(x = "", y = mpg), data = mtcars) +
stat_boxplot(geom ='errorbar', width = 0.4) +
geom_boxplot(outlier.colour = "red") +
coord_flip() +
scale_y_continuous(limits = c((min(mtcars$mpg)),(max(mtcars$mpg))),
breaks = pretty(mtcars$mpg, n = 10)) +
stat_summary(fun.y = mean, colour = "purple", geom = "point",
shape = 18, size = 3) +
labs(x = "", y = "mpg")
grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2), size = "first"))