在 facet_wrap 中减小轴标签和轴之间的区域
Reducing the area between axis labels and axis in facet_wrap
我正在使用facet_wrap
显示两个图,我想减少横轴和轴上的年份之间的距离,使年份更接近轴。有办法吗?
ggplot( df,
aes(x=year, y = value)) +
geom_area(aes(fill = variable)) +
facet_wrap(~ scenario, ncol=3) +
ylab("") +
xlab("") +
theme_bw() +
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(axis.text.x = element_text(angle = 90)) +
theme(axis.title.y = element_text(angle = 0)) +
theme(axis.line = element_line(),
strip.background = element_blank(),
panel.margin = unit(2, "lines"))
这是数据集:
df <- structure(list(country = c("CAN", "CAN", "CAN", "CAN", "CAN",
"CAN", "CAN", "CAN"), year = c(2030, 2030, 2030, 2030, 2040,
2040, 2040, 2040), scenario = structure(c(2L, 2L, 1L, 1L, 2L,
2L, 1L, 1L), .Label = c("BAU", "2Ci", "2Cd"), class = "factor"),
variable = structure(c(5L, 2L, 5L, 2L, 5L, 2L, 5L, 2L), .Label = c("ELEC",
"GAS", "ROIL", "OIL", "COAL"), class = "factor"), value = c(0.128654289458377,
2.37568827939126, 0.146615100987535, 2.86487702956444, 0.0980137869955521,
1.62493493094997, 0.150757647986727, 2.74361420537482), unit = c("Exojoules",
"Exojoules", "Exojoules", "Exojoules", "Exojoules", "Exojoules",
"Exojoules", "Exojoules"), sector = c("ECON", "ECON", "ECON",
"ECON", "ECON", "ECON", "ECON", "ECON")), row.names = c(NA,
-8L), groups = structure(list(country = c("CAN", "CAN", "CAN",
"CAN"), year = c(2030, 2030, 2040, 2040), scenario = c("2Ci",
"BAU", "2Ci", "BAU"), .rows = list(1:2, 3:4, 5:6, 7:8)), row.names = c(NA,
-4L), class = c("tbl_df", "tbl", "data.frame")), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
scale_y_continuous(expand = expand_scale(mult = c(0, 0.05))) +
应该使基线和数据之间没有 space,顶部的填充与默认情况下相同。
我正在使用facet_wrap
显示两个图,我想减少横轴和轴上的年份之间的距离,使年份更接近轴。有办法吗?
ggplot( df,
aes(x=year, y = value)) +
geom_area(aes(fill = variable)) +
facet_wrap(~ scenario, ncol=3) +
ylab("") +
xlab("") +
theme_bw() +
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(axis.text.x = element_text(angle = 90)) +
theme(axis.title.y = element_text(angle = 0)) +
theme(axis.line = element_line(),
strip.background = element_blank(),
panel.margin = unit(2, "lines"))
这是数据集:
df <- structure(list(country = c("CAN", "CAN", "CAN", "CAN", "CAN",
"CAN", "CAN", "CAN"), year = c(2030, 2030, 2030, 2030, 2040,
2040, 2040, 2040), scenario = structure(c(2L, 2L, 1L, 1L, 2L,
2L, 1L, 1L), .Label = c("BAU", "2Ci", "2Cd"), class = "factor"),
variable = structure(c(5L, 2L, 5L, 2L, 5L, 2L, 5L, 2L), .Label = c("ELEC",
"GAS", "ROIL", "OIL", "COAL"), class = "factor"), value = c(0.128654289458377,
2.37568827939126, 0.146615100987535, 2.86487702956444, 0.0980137869955521,
1.62493493094997, 0.150757647986727, 2.74361420537482), unit = c("Exojoules",
"Exojoules", "Exojoules", "Exojoules", "Exojoules", "Exojoules",
"Exojoules", "Exojoules"), sector = c("ECON", "ECON", "ECON",
"ECON", "ECON", "ECON", "ECON", "ECON")), row.names = c(NA,
-8L), groups = structure(list(country = c("CAN", "CAN", "CAN",
"CAN"), year = c(2030, 2030, 2040, 2040), scenario = c("2Ci",
"BAU", "2Ci", "BAU"), .rows = list(1:2, 3:4, 5:6, 7:8)), row.names = c(NA,
-4L), class = c("tbl_df", "tbl", "data.frame")), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
scale_y_continuous(expand = expand_scale(mult = c(0, 0.05))) +
应该使基线和数据之间没有 space,顶部的填充与默认情况下相同。