可以创建插图吗? [英] It is possible to create inset graphs?

查看:18
本文介绍了可以创建插图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当您使用 par( fig=c( ... ), new=T ) 时,您可以创建插图.但是,我想知道是否可以使用 ggplot2 库来创建插入"图.

I know that when you use par( fig=c( ... ), new=T ), you can create inset graphs. However, I was wondering if it is possible to use ggplot2 library to create 'inset' graphs.

更新 1:我尝试将 par() 与 ggplot2 一起使用,但它不起作用.

UPDATE 1: I tried using the par() with ggplot2, but it does not work.

更新 2:我在 ggplot2 GoogleGroups 找到了一个有效的解决方案,使用grid::viewport().

UPDATE 2: I found a working solution at ggplot2 GoogleGroups using grid::viewport().

推荐答案

Section 8.4 of 这本书解释了如何做到这一点.诀窍是使用 grid 包的 viewports.

Section 8.4 of the book explains how to do this. The trick is to use the grid package's viewports.

#Any old plot
a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()

#A viewport taking up a fraction of the plot area
vp <- viewport(width = 0.4, height = 0.4, x = 0.8, y = 0.2)

#Just draw the plot twice
png("test.png")
print(a_plot)
print(a_plot, vp = vp)
dev.off()

这篇关于可以创建插图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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