R 减少轴标签和面_包裹中的轴之间的面积
我正在使用R 减少轴标签和面_包裹中的轴之间的面积,r,facet-wrap,R,Facet Wrap,我正在使用facet\u wrap显示两个图,我希望缩短水平轴上年份与轴之间的距离,使年份更接近轴。有办法做到这一点吗 ggplot( df, aes(x=year, y = value)) + geom_area(aes(fill = variable)) + facet_wrap(~ scenario, ncol=3) + ylab("") + xlab("") + theme_bw() + theme(
facet\u 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"))
df
应该使基线和数据之间没有空格,顶部的填充与默认情况下相同
应该使基线和数据之间没有空格,顶部的填充与默认情况下相同
scale_y_continuous(expand = expand_scale(mult = c(0, 0.05))) +