How to make a chain of ggplots and draw arrows bet

2020-07-18 10:45发布

问题:

For a project I need to draw some plots and put arrows between them as and indication of a sequence. I was wondering if I could do that with ggplot. Is it possible to draw a clean, big arrow with ggplot2 and add it two the final multiplot?

As an example I use this code to draw a plot:

library(ggplot2)
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()

For the project I need to draw three plots like that. The result should be something like this:

Does anyone have a solution? Many thanks in advance!

回答1:

Here's one approach:

library(ggplot2)
library(gridExtra)
library(grid)
library(png)
download.file("https://www.wpclipart.com/signs_symbol/arrows/arrow_comic/Arrow_comic_right_gray.png",
              tf <- tempfile(fileext = ".png"),
              mode="wb")
arrow <- rasterGrob(readPNG(tf))
p <- ggplot(diamonds, aes(clarity, fill=cut)) + 
  geom_bar() 
grid.arrange(p + guides(fill = "none"), 
             arrow, 
             p + guides(fill = "none"), 
             arrow, 
             p, 
             ncol=5, widths=c(2/10, 1.75/10, 2/10, 1.75/10, 2.5/10))