Search code examples
rfacet-wrap

Removing additional lines below horizontal axis labels in facet_wrap


I am using geom_col and facet_wrap to plot 14 graphs together. I was wondering if there is a way to remove the horizontal lines below the horizontal axis labels?

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")) 

enter image description here

Here is the data:

    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))

Solution

  • Remove this line: axis.line = element_line() or change it to axis.line = element_blank()

    enter image description here