Add check marks without labels at the top of the strip in ggplot2

As the title says, I would like to add ticks to the top of the dash plot in ggplot2. The result will look something like this: (hiding the actual schedule due to sensitive information). Is there a function in ggplot2 that does this?

example bar plot

+2


source to share


1 answer


I adapted Baptiste's solution from the link Show y-axis for each subheading while cutting . The idea (I think) is to extract the x-axis of the grob and add it to the top of the graph.

library(ggplot2)
library(gtable)

# plot
p1 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar() + theme_bw()


gg <- ggplotGrob(p1)

axis <- gtable_filter(gg ,"axis-b")[["grobs"]][[1]][["children"]][["axis"]][1,]
panels <- subset(gg$layout, name == "panel")
gg <- gtable_add_grob(gg, grobs=axis, name="ticks", t = panels$t-1, l=panels$l)

grid.newpage()
grid.draw(gg)

      



enter image description here

+1


source







All Articles