ggplot does not draw axis lines by default. If you desperately miss them, this post is for you. Adding X- and Y-axis lines to your plot implies that you modify the theme of the plot itself. Nothing very complicated about it, as you will see further below.

Let’s start with the code for a reference plot. This plot is stored in the object baseplot so that we can reuse it throughout the whole tutorial:

baseplot <- ggplot(df, aes(values1, values2)) +
  geom_point(size=2)
baseplot



To add both X- and Y-axis lines to your plot, add an extra line of code and write theme(axis.line = element_line()). In the parentheses, you may add additional arguments for modifying the size/thickness (size=), color (color=) and pattern of the line (linetype=):

baseplot +
  theme(axis.line = element_line(linetype = "solid", size = 1, colour = "darkblue"))



If you wish to use different parameters for each axis, use axis.line.x and axis.line.y to operate on the X- and Y-axis separately:

baseplot +
  theme(axis.line.y = element_line(size = 1, colour = "darkblue", linetype = "solid"), 
        axis.line.x = element_line(size = 1.25, colour = "red", linetype = "dotted"))