2016-10-31 5 views
1

Ich kann einen Inset drucken und ein Raster aus Plots in ggplots erstellen. Aber ich bin nicht in der Lage, ein Gitter mit einem Diagramm auf der linken Seite und 2 Grafiken auf der rechten Seite eine volle Größe und die andere in "Einfügung" zu erstellen.ggplot2 füge zwei Plots in grid.arrange mit einer Einfügung in die zweite in R hinzu

a_plot <- ggplot(cars, aes(speed, dist)) + geom_line() 

#The inset 
print(a_plot);print(a_plot, vp = vp) 

enter image description here

# the Grid 
lay <- rbind(c(1,1,1,2,2,2), 
      c(1,1,1,2,2,2), 
      c(1,1,1,2,2,2), 
      c(1,1,1,2,2,2)) 
grid.arrange(a_plot, a_plot,layout_matrix = lay) 

enter image description here

Aber ich möchte dies haben:

enter image description here

Wie kann ich das tun?

funktioniert das nicht

grid.arrange(a_plot, a_plot,print(a_plot, vp = vp),layout_matrix = lay) 

Ich versuchte this und es entweder nicht funktioniert hat.

+0

Ich bin in der Lage, dies zu verwenden, um einen Einsatz zu schaffen, aber es nicht danach auf einem Gitter zu setzen ... –

Antwort

1
a_plot <- ggplot(cars, aes(speed, dist)) + geom_line() 
b_plot <- a_plot + annotation_custom(grob = rectGrob(), 
         xmin = 15, xmax = Inf, ymin=-Inf, ymax=25) 


grid.arrange(a_plot, b_plot, ncol=2) 

enter image description here

+0

b_plot <- a_plot + coord_cartesian() + annotation_custom (grob = ggplotGrob (a_plot), xmin = -90,2, xmax = Inf, ymin = -Inf, ymax = -0,8) 'coord_cartesian()' ist möglicherweise erforderlich, wenn das Objekt eine Map ist. Verwenden Sie anstelle von 'reacGrob()' 'ggplotGrob()' –

Verwandte Themen