这是我想要实现的一个例子,但是使用PerformanceAnalytics
。
library(PerformanceAnalytics)
data(edhec)
chart.TimeSeries(edhec)
这给出了图表:你可以看到标题的左对齐和日期右对齐,在图的主面板中,这是“pre-ggplot”R量子包的标准(参见例如quantmod
)。
我的问题是如何使用ggplot2
,在情节的title
或subtitle
中做到这一点?
编辑。澄清了我在文本理由方面的要求。
你可以手动cowplot::draw_text
library(ggplot2)
library(cowplot)
p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(title = "")
ggdraw(p) +
draw_text("Miles/gallon vs. weight (in 1000 lbs)", x = 0.01, y = 0.99, hjust = 0, vjust = 1) +
draw_text("Dataset: mtcars", x = 0.99, y = 0.99, hjust = 1, vjust = 1)
labs(title = "")
是为标题创造空白空间所必需的。