r - Bring title to the top right corner -
how can modify below code bring title top right corner.
value <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7) names.arg =c("0-15","15-19","20-24","25-29","30-34", "35-39","40-44","45- 49","50-54","55-59","60-64","65 jahre oder Älter") df <- data.frame(names.arg = names.arg, value = value) p1 <- ggplot(df, aes(x=names.arg, y=value)) + geom_bar(stat = "identity") save(p1, file = "p1.png") value2 <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7) names2 =c("0-15","15-19","20-24","25-29","30-34", "35-39","40-44","45- 49","50-54","55-59","60-64","65 jahre oder Älter") df2 <- data.frame(names = names2, value = value2) p2 <- ggplot(df2, aes(x=names, y=value)) + geom_bar(stat = "identity", fill = "red") title <- textgrob("graph 1.2: plot", gp = gpar(fontsize=13,font=4)) grid.arrange(p1,p2,nrow=2,top = title)
reference "error in grid.arrage - arrangegrob() function"
instead of gridextra
use package cowplot
:
#create grid pgrid <- plot_grid(p1, p2, nrow=2) #create title title <- ggdraw() + draw_label("graph 1.2: plot", hjust=-5, fontface=4, size=13) #combine plots , title plot_grid(title, pgrid, ncol=1, rel_heights=c(0.1, 1))
Comments
Post a Comment