0
有沒有辦法使用ggplot的facet_grid在圖表頂部的標籤和圖的邊距之間添加空格。以下是一個可重複的例子。r ggplot2 facet_grid如何添加圖表頂部和邊框之間的空間
library(dplyr)
library(ggplot2)
Titanic %>% as.data.frame() %>%
filter(Survived == "Yes") %>%
mutate(FreqSurvived = ifelse(Freq > 100, Freq*1e+04,Freq)) %>%
ggplot(aes(x = Age, y = FreqSurvived, fill = Sex)) +
geom_bar(stat = "identity", position = "dodge") +
facet_grid(Class ~ ., scales = "free") +
theme_bw() +
geom_text(aes(label = prettyNum(FreqSurvived,big.mark = ",")), vjust = 0, position = position_dodge(0.9), size = 2)
生成的圖表的標籤旁邊有數字。
要詳細一點:'expand'在這種情況下'0.1 * y_range + 0'到每個y軸添加(默認是c(0.05,0)), – GGamba