删除 facet_wrap 中水平轴标签下方的附加行
Removing additional lines below horizontal axis labels in facet_wrap
我正在使用 geom_col
和 facet_wrap
绘制 14 个图形。我想知道有没有办法去掉水平轴标签下面的水平线?
ggplot(df) +
geom_col(aes(year, value, fill =as.factor(year)), size=8, width=6.5) +
facet_wrap(.~ sector, scales="free_x" ,ncol=14, strip.position="bottom") +
ylab("") +
xlab("") +
labs(x = "", colour = "") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(strip.background = element_blank()) +
theme(axis.line = element_line(),
strip.background = element_blank(),
panel.spacing = unit(1, "lines"),
strip.text = element_text(size = 8, angle = 90, face = "bold",hjust = 1, ),
axis.text.x.bottom = element_blank() ) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
guides(fill=guide_legend(title=" ")) +
theme(panel.spacing = unit(2, "lines")) +
theme(panel.spacing.x = unit(0.1, "lines")) +
theme(panel.spacing.y = unit(2, "lines")) +
theme(axis.text.x = element_text(color = "black", size = 8, angle = 90, hjust = 1, vjust = 1, face = "bold")) +
theme(axis.text.y = element_text(color = "black", size = 8, angle = 0, hjust = 1, vjust = 1, face = "bold"))
这是数据:
df <- structure(list(sector = c("CROP", "CROP", "LIVE", "LIVE", "FORS",
"FORS", "FOOD", "FOOD", "COAL", "COAL", "OIL", "OIL", "ROIL",
"ROIL", "GAS", "GAS", "ELEC", "ELEC", "EINT", "EINT", "OTHR",
"OTHR", "SERV", "SERV", "TRAN", "TRAN", "DWE", "DWE"), year = c(2040,
2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050,
2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040,
2050, 2040, 2050, 2040, 2050), value = c(-13.23, -17.14, 3.41,
84.26, -9.67, -27.67, -5.09, -16.39, -48.75, -97.59, -37.47,
-79.16, -39.48, 63.59, -41.97, -90.65, 15.08, 67.9, -5.23, -16.37,
-6.83, -13.84, -7.06, -16.38, 17.72, 16.43, -4.64, -10.64)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -28L))
删除此行:axis.line = element_line()
或将其更改为 axis.line = element_blank()
我正在使用 geom_col
和 facet_wrap
绘制 14 个图形。我想知道有没有办法去掉水平轴标签下面的水平线?
ggplot(df) +
geom_col(aes(year, value, fill =as.factor(year)), size=8, width=6.5) +
facet_wrap(.~ sector, scales="free_x" ,ncol=14, strip.position="bottom") +
ylab("") +
xlab("") +
labs(x = "", colour = "") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
theme(strip.background = element_blank()) +
theme(axis.line = element_line(),
strip.background = element_blank(),
panel.spacing = unit(1, "lines"),
strip.text = element_text(size = 8, angle = 90, face = "bold",hjust = 1, ),
axis.text.x.bottom = element_blank() ) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
guides(fill=guide_legend(title=" ")) +
theme(panel.spacing = unit(2, "lines")) +
theme(panel.spacing.x = unit(0.1, "lines")) +
theme(panel.spacing.y = unit(2, "lines")) +
theme(axis.text.x = element_text(color = "black", size = 8, angle = 90, hjust = 1, vjust = 1, face = "bold")) +
theme(axis.text.y = element_text(color = "black", size = 8, angle = 0, hjust = 1, vjust = 1, face = "bold"))
这是数据:
df <- structure(list(sector = c("CROP", "CROP", "LIVE", "LIVE", "FORS",
"FORS", "FOOD", "FOOD", "COAL", "COAL", "OIL", "OIL", "ROIL",
"ROIL", "GAS", "GAS", "ELEC", "ELEC", "EINT", "EINT", "OTHR",
"OTHR", "SERV", "SERV", "TRAN", "TRAN", "DWE", "DWE"), year = c(2040,
2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050,
2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040, 2050, 2040,
2050, 2040, 2050, 2040, 2050), value = c(-13.23, -17.14, 3.41,
84.26, -9.67, -27.67, -5.09, -16.39, -48.75, -97.59, -37.47,
-79.16, -39.48, 63.59, -41.97, -90.65, 15.08, 67.9, -5.23, -16.37,
-6.83, -13.84, -7.06, -16.38, 17.72, 16.43, -4.64, -10.64)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -28L))
删除此行:axis.line = element_line()
或将其更改为 axis.line = element_blank()