Cat*_*pos 6 r indentation figures ggplot2
我正在为出版物生成图表,我希望能够在ggplot本身标注图形的面板(而不是导出到出版商等),以便它们在最终文档中整齐地整合在一起.我打算通过在标题中添加一个字母("A")来尝试这样做,但我希望我的标题居中,我想要左上角的字母.
# base graph:
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species))+
geom_jitter(size = 6.5)+
ggtitle("A \n \n The Actual Long, Normal Title of Titliness")+
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 30),
axis.ticks = element_blank(),
legend.text = element_text(size = 25),
axis.title = element_text(size = 25, face = "bold"),
axis.text = element_text(size = 25, vjust = 0.05),
legend.position = "bottom")
Run Code Online (Sandbox Code Playgroud)

现在,如果我愿意通过手工间隔每个标题"伪造它",我可以让它起作用,但这似乎是时间密集和粗糙的.
# sloppy solution
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species))+
geom_jitter(size = 6.5)+
ggtitle("A \n \n The Actual Long, Normal Title of Titliness")+
theme(plot.title = element_text(hjust = 0,face = "bold", size = 30),
axis.ticks = element_blank(),
legend.text = element_text(size = 25),
axis.title = element_text(size = 25, face = "bold"),
axis.text = element_text(size = 25, vjust = 0.05),
legend.position = "bottom")
Run Code Online (Sandbox Code Playgroud)

有没有办法单独调用标题的每个"行"以获得自己的hjust值?
还有其他创意解决方案
另外,我在mtext中看到了潜力(使用表达式拆分轴标签),但无法弄清楚如何使用ggplot2实现它(与基本绘图函数相比......似乎它们不兼容).这篇文章是各种有趣的(多线ggplot标题与不同的字体大小,面部等),但我仍然是R的新手,我无法弄清楚如何编辑这个聪明的东西来改变缩进.
谢谢!
Cla*_*lke 11
更新:由于ggplot2 3.0.0现在支持绘图标签,请参阅此答案.
以下是我将如何使用我专门为此目的编写的cowplot包.请注意,您获得了一个干净的主题作为奖励.
library(cowplot)
p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species)) +
geom_jitter(size = 3.5) +
ggtitle("The Actual Long, Normal Title of Titliness")
# add one label to one plot
ggdraw(p) + draw_plot_label("A")
Run Code Online (Sandbox Code Playgroud)
# place multiple plots into a grid, with labels
plot_grid(p, p, p, p, labels = "AUTO")
Run Code Online (Sandbox Code Playgroud)
然后,您希望使用该save_plot函数来保存图而不是ggsave,因为它save_plot具有默认值和参数,可帮助您获得相对于主题的缩放,特别是对于网格中的图.
Dro*_*let 10
因为ggplot2 3.0.0,使用tag标签有一种本地方式:
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species, shape = Species)) +
geom_point() +
labs(title = "The Actual Long, Normal Title of Titliness",
tag = "A")
Run Code Online (Sandbox Code Playgroud)