【问题标题】:Replace title to the bottom of the graph in ggplot [duplicate]将标题替换为ggplot中图表的底部[重复]
【发布时间】:2018-06-19 08:22:53
【问题描述】:

在我的脑海中,这确实是一个简单的调整,但我找不到一个简单的论据来做到这一点。我希望标题不在此图的顶部,而是在底部。我可以使用任何文本行来快速高效地做到这一点吗?

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))

【问题讨论】:

  • 请参阅this answer 了解一些选项,例如使用caption 而不是title

标签: r ggplot2 graph title


【解决方案1】:

您可以使用库 gridExtra 中的 grid.arrange()

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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    相关资源
    最近更新 更多