如何制作ggplots链并在它们之间绘制箭头? [英] How to make a chain of ggplots and draw arrows between them?

查看:93
本文介绍了如何制作ggplots链并在它们之间绘制箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个项目,我需要画一些图,并在它们之间放箭头,以表示顺序。我想知道是否可以使用ggplot做到这一点。是否可以用ggplot2绘制干净的大箭头并将其添加为最终的多图两个?

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!

推荐答案

这里是一种方法:

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

< a href = https://i.stack.imgur.com/yUj4k.gif rel = noreferrer>

这篇关于如何制作ggplots链并在它们之间绘制箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆