Putting x-axis at top of ggplot2 chart

后端 未结 5 1504
逝去的感伤
逝去的感伤 2020-12-13 08:23

I feel like this should be obvious... all I\'m trying to do is to remove the x-axis from the bottom of my graph and add it to the top.

Here is a reproducible examp

5条回答
  •  余生分开走
    2020-12-13 09:14

    The only way I can think to do this is to go wild with the vjust theme option for the axis labels (and the axis title as well, I suppose). Something like:

    df <- data.frame(x = 1:10, y = (1:10)^2)       # example data
    
    p <- ggplot(df, aes(x = x, y = y)) + geom_point() +
        theme(
            axis.text.x = element_text(vjust = -5),
            axis.title.x = element_text(vjust = -5))
    

    vjust doesn't work with element_text, though, so I"m stuck on moving the axis ticks.

提交回复
热议问题