# Create sample data
set.seed(5642)
sample_data <- data.frame(name=c("Geek1","Geek2",
"Geek3","Geek4","Geeek5") ,
value=c(31,12,15,28,45))
# Load ggplot2 and cowplot
library("ggplot2")
library("cowplot")
# Create both plot and store in variable without legend
plot1<-ggplot(sample_data, aes(x=name, y=value, fill=name)) +
geom_bar(stat = "identity") +
theme(legend.position = "none")
plot2<-ggplot(sample_data, aes(x = name, y=value, fill=name)) +
geom_point(aes(colour = factor(name)), size = 6)+
theme(legend.position = "none")
# combine both plot using plot_grid()
combined_plot<-plot_grid(plot1, plot2,ncol=2)
# create title for plot
title <- ggdraw() +
draw_label(
"Two Plots together with shared title",
fontface = 'bold',
x = 0,
hjust = 0,
size = 24,
)
# Combine combined plot and title using plot_grid()
plot_grid(title, combined_plot ,ncol=1,rel_heights = c(0.1, 1))