Moving x or y axis together with tick labels to the middle of a single ggplot (no facets)

后端 未结 4 1054
不思量自难忘°
不思量自难忘° 2020-12-03 06:35

I made the following plot in Excel:

But then I thought I would make it prettier by using ggplot. I got this far:

If you\'re curious, the da

4条回答
  •  星月不相逢
    2020-12-03 06:45

    just to complete baptiste's excellent answer with the equivalent for moving the y axis:

    shift_axis_x <- function(p, x=0){
          g <- ggplotGrob(p)
          dummy <- data.frame(x=x)
          ax <- g[["grobs"]][g$layout$name == "axis-l"][[1]]
          p + annotation_custom(grid::grobTree(ax, vp = grid::viewport(x=1, width = sum(ax$height))), 
                                xmax=x, xmin=x) +
            geom_vline(aes(xintercept=x), data = dummy) +
            theme(axis.text.y = element_blank(), 
                  axis.ticks.y=element_blank())
        }
    

提交回复
热议问题