我想显示一个相对较长的标签,并且不希望这个标签占用图表的空间。
例子:
library(ggplot2)
out <- ggplot(economics, aes(x=date,y=unemploy)) +
geom_line() +
labs(title="US unemployment rate",
subtitle="(%)",
caption="Source: St. Louis Fed.\n Last observation: April 2014.",
tag="us_unempl.pdf (last update: 2019-01-15, 22:30)") +
theme(plot.caption=element_text(hjust=0),
plot.tag=element_text(size=rel(1)),
plot.tag.position="bottomright")
print(out)
Run Code Online (Sandbox Code Playgroud)
在此示例中,相对较宽的标签会导致实际图表的空间大量损失,因为图表的右边距向左移动。
如何在图表下方显示标签 - 理想情况下与标题第二行相对,或者与标题下方绘图的右边缘对齐?
注意:我需要其他信息的标题(例如在我的示例中),否则在plot.caption中使用 hjust=1 显然是一个自然的解决方案。