Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to create inset graphs?

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.

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

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

like image 972
Sam Avatar asked Mar 07 '11 12:03

Sam


People also ask

What is an inset graph?

29.7. An inset plot is a layer which is added to an existing layer in a graph window. The dimensions of the inset layer are reduced so that the "host" layer remains at least partially visible in the graph window.

How do I make an inset graph in origin?

Click Add Inset Graph or Add Inset with Data button on the Graph toolbar. Then use Scale In tool to show different range of data. Another way (with more steps) of doing this is to select Insert: New Layer(Axes): Bottom-X Left-Y to add a second layer.

What is inset in R?

The optional inset argument specifies how far the legend is inset from the plot margins. If a single value is given, it is used for both margins; if two values are given, the first is used for x - distance, the second for y -distance.


1 Answers

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() 
like image 90
Richie Cotton Avatar answered Oct 07 '22 21:10

Richie Cotton