在我看来,这实际上是一个简单的调整,但我找不到一个简单的论据来做到这一点。我希望标题不在顶部,而是在图表的底部。我能用这个快速有效的任何文本行吗?
library(tidyverse)
set.seed(20)
df <- data.frame(expl = rbinom(n=100, size = 1, prob=0.08),
resp = sample(50:100, size = 100, replace = T))
df$expl <- factor(df$expl, levels = c("1", "0"))
ggplot(df, aes(x = resp, alpha = factor(expl, labels = c("Condition 1", "Condition 2")))) +
geom_histogram(fill = "#bebada", bins = 10) +
labs(title = "I want this title to the bottom of the graph") +
labs(alpha = "Condition") +
scale_alpha_manual(values = c(0.5, 1))
答案 0 :(得分:0)
您可以使用库grid.arrange()
中的gridExtra
。
p<-ggplot(df, aes(x = resp, alpha = factor(expl, labels = c("Condition 1", "Condition 2")))) +
geom_histogram(fill = "#bebada", bins = 10) +
labs(alpha = "Condition") +
scale_alpha_manual(values = c(0.5, 1))
library(gridExtra)
grid.arrange(p, bottom="I want this title to the bottom of the graph")
如果您不想安装库,则只需添加前缀gridExtra::grid.arrange(p, bottom="I want this title to the bottom of the graph")