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

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

问题描述

我知道当您使用 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()

推荐答案

本书的第8.4节介绍了如何执行此操作。诀窍是使用 grid 包的 viewport s。

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天全站免登陆