Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a chain of ggplots and draw arrows between them?

Tags:

r

ggplot2

drawing

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:

enter image description here

Does anyone have a solution? Many thanks in advance!

like image 538
rdatasculptor Avatar asked Jan 06 '23 20:01

rdatasculptor


1 Answers

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))

enter image description here

like image 151
lukeA Avatar answered Jan 18 '23 13:01

lukeA