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

孤人 提交于 2019-12-21 20:37:46

问题


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



来源:https://stackoverflow.com/questions/34744655/how-to-make-a-chain-of-ggplots-and-draw-arrows-between-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!