【发布时间】:2012-07-30 15:13:13
【问题描述】:
我正在使用 ggplot2 来改进降水条形图。
这是我想要实现的可重现示例:
library(ggplot2)
library(gridExtra)
secu <- seq(1, 16, by=2)
melt.d <- data.frame(y=secu, x=LETTERS[1:8])
m <- ggplot(melt.d, aes(x=x, y=y)) +
geom_bar(fill="darkblue") +
labs(x="Weather stations", y="Accumulated Rainfall [mm]") +
opts(axis.text.x=theme_text(angle=-45, hjust=0, vjust=1),
title=expression("Rainfall"), plot.margin = unit(c(1.5, 1, 1, 1), "cm"),
plot.title = theme_text(size = 25, face = "bold", colour = "black", vjust = 5))
z <- arrangeGrob(m, sub = textGrob("Location", x = 0, hjust = -3.5, vjust = -33, gp = gpar(fontsize = 18, col = "gray40"))) #Or guessing x and y with just option
z
我不知道如何避免在 ggplot2 上的 hjust 和 vjust 上使用猜测数字?有没有更好的方式放字幕(不只是使用\n,而是使用不同文字颜色和大小的字幕)?
我需要能够与 ggsave 一起使用才能拥有一个 pdf 文件。
这里有两个相关的问题:
Add a footnote citation outside of plot area in R?
How can I add a subtitle and change the font size of ggplot plots in R?
感谢您的帮助。
【问题讨论】:
-
vjust=-33 在 Linux 上为我工作。我知道 sub 是为了低于情节,但这是我得到我想要的东西的唯一方法。
-
由于某种原因,这使我的情节非常小,并在图表下方创建了一个巨大的空间
-
@hrbrmstr 的回答似乎是当今的必经之路