【发布时间】:2018-02-27 10:49:06
【问题描述】:
在 ggplot - plot.title = element_text(hjust = 0.5) 中居中对齐绘图标题的“lege artis”方式 - 将标题居中于绘图区域不包括轴标签。
当轴标签很长时,这可能会变得很难看,例如 Mary Poppins Soundtrack 中的歌曲与字符长度的关系。
library(tidyverse)
mary_poppins <- data_frame(song = c("Overture", "Sister Suffragette", "The Life I Lead", "The Perfect Nanny", "A Spoonful of Sugar", "Pavement Artist", "Jolly Holiday", "Supercalifragilisticexpialidocious", "Stay Awake", "I Love to Laugh", "A British Bank", "Feed the Birds ", "Fidelity Fiduciary Bank", "Chim Chim Cher-ee", "Step in Time", "A Man Has Dreams", "Let's Go Fly a Kite"
))
mary_poppins <- mary_poppins %>%
mutate(len = nchar(song))
ggplot(data = mary_poppins, aes(x = reorder(song, len), y = len)) +
geom_col(fill = "firebrick") +
coord_flip() +
theme_light() +
theme(axis.title.y = element_blank(),
axis.text = element_text(size = rel(1.5)),
plot.title = element_text(size = rel(2.5), face = "bold", hjust = 0.5,
margin = margin(t = 10, b = 20, unit = "pt"))) +
ggtitle("Mary Poppins") +
ylab("Lenght of title (characters)")
有没有办法让标题在总绘图区域上居中,即包括轴标签所占据的区域?
【问题讨论】:
标签: r ggplot2 data-visualization