非分面图中的分面样式标题

The*_*aly 6 r ggplot2

我非常喜欢分面图标题的风格:

require(ggplot2)
df <- data.frame(x = rnorm(1E3), labels = as.factor(c(rep("plot1",500), rep("plot2",500))));
ggplot(df, aes(x=x) ) + geom_histogram() +facet_wrap(~labels)
Run Code Online (Sandbox Code Playgroud)

刻面

我想以类似的方式格式化其他情节的标题。当我将 ggtitle() 添加到图中时,我得到以下结果:

ggplot(df, aes(x=x) ) + geom_histogram() +ggtitle('plot1 and plot2')

标题

如何格式化 ggtitle 标题使其看起来像facet_wrap 标题?

谢谢你!

aos*_*ith 4

如果您希望内容看起来像条带标签,您可以为标题创建一个新列,其中包含单个组并使用该变量进行分面。

本质上是使用带有假变量的构面来获得您喜欢的外观。

df$overall = "plot1 and plot2"

ggplot(df, aes(x=x) ) + 
     geom_histogram() +
     facet_wrap(~overall)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述