如何制作一系列 ggplots 并在它们之间绘制箭头?
How to make a chain of ggplots and draw arrows between them?
对于一个项目,我需要绘制一些图并在它们之间放置箭头作为顺序指示。我想知道我是否可以用 ggplot 做到这一点。是否可以使用 ggplot2 绘制一个干净的大箭头并将其添加到最终的多图中?
作为示例,我使用这段代码绘制了一个图:
library(ggplot2)
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
对于这个项目,我需要绘制三个这样的图。结果应该是这样的:
有人有解决办法吗?非常感谢!
这是一种方法:
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))
对于一个项目,我需要绘制一些图并在它们之间放置箭头作为顺序指示。我想知道我是否可以用 ggplot 做到这一点。是否可以使用 ggplot2 绘制一个干净的大箭头并将其添加到最终的多图中?
作为示例,我使用这段代码绘制了一个图:
library(ggplot2)
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
对于这个项目,我需要绘制三个这样的图。结果应该是这样的:
有人有解决办法吗?非常感谢!
这是一种方法:
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))