Мне трудно сделать заголовок легенды по центру относительно клавиш легенды, когда заголовок легенды длинный. Существует вопрос от год назад, который работает для коротких заголовков, но, похоже, не подходит для длинных.
Пример, сначала с коротким заголовком легенды:
library(ggplot2)
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Petal.Width)) + geom_point(size = 3) +
scale_color_distiller(palette = "YlGn", type = "seq", direction = -1,
name = "A") +
theme(legend.title.align = 0.5)
Все как и ожидалось, заголовок легенды расположен над ключом легенды.
Теперь то же самое с длинным названием легенды:
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Petal.Width)) + geom_point(size = 3) +
scale_color_distiller(palette = "YlGn", type = "seq", direction = -1,
name = "Long legend heading\nShould be centered") +
theme(legend.title.align = 0.5)
Мы видим, что текст выровнен по центру, но не относительно ключа легенды. Я пытался изменить другие параметры темы, такие как legend.justification = "center"
, но ни одна из них, похоже, не сдвинула ключ с самой левой позиции в поле легенды.
Пара комментариев:
Я пользуюсь версией разработки ggplot2 v2.2.1.9000, выпущенной несколько дней назад.
Мне особенно нужно решение для непрерывной цветовой палитры.