0
我想在标题(轴标题和绘图标题)和绘图边缘之间创建空间。我试过axis.title
和plot.title
,但没有运气。当我尝试vjust
的各种值时,剧情没有真正改变。我也试过plot.margin
,但似乎也没有发生。调整标题和绘图边缘之间的空白
数据:
data = data.frame(Category = c(0,1), value = c(40000, 120000))
data$Category = factor(data$Category, levels = c(0,1), labels = c("One-time", "Repeat"))
简介:
p = ggplot(data, aes(Category, Value)) +
geom_bar(stat = "identity", width = 0.5, position=position_dodge(width=0.9)) +
geom_text(aes(label=Value), position=position_dodge(width=0.9), family = "mono", vjust=-0.5) +
ggtitle("Title") +
scale_y_continuous(expand = c(0,0), limits = c(0,150000)) +
scale_x_discrete(expand = c(0,0), limits = c("One-time", "Repeat")) +
xlab("X axis Title") +
ylab("Y axis Title")
主题:
p + theme(
panel.grid.major = element_line(linetype = "blank"),
panel.grid.minor = element_line(linetype = "blank"),
axis.title = element_text(family = "sans", size = 15),
axis.text = element_text(family = "mono", size = 12),
plot.title = element_text(family = "sans", size = 18),
panel.background = element_rect(fill = NA)
)
嘿,那工作!似乎margin不能设置在更高级别的'axis.title'上,而是需要设置在各个轴级上('axis.title.x.'和'axis.title.y')。 – rnewbie