ggplot2, axis not showing after using theme(axis.line=element_line())

The bug was fixed in ggplot2 v2.2.0 There is no longer a need to specify axis lines separately.

I think this is a bug in ggplot2 v2.1.0. (See this bug report and this one.) A workaround is to set the x-axis and y-axis lines separately.

  library(ggplot2)

  ggplot(data = mpg, aes(x = hwy, y = displ)) + 
  geom_point() + 
  theme_bw() + 
  theme(plot.background = element_blank(),
         panel.grid.major = element_blank(),
         panel.grid.minor = element_blank() )+
  theme(panel.border= element_blank())+
  theme(axis.line.x = element_line(color="black", size = 2),
        axis.line.y = element_line(color="black", size = 2))

Leave a Comment