0

enter image description here

I,m trying to get these figures together in one figure, but I would like to have a shared x-axis below all 3, without the last figure to have a different size than the other 2. Similar for the middle figure with the legend, I would like the legend to be outide the 6 figure, without affecting the size of one of the figures. I use arrangeGrob(plot1, plot2, ...., plot6) right now.

If anyone has a sollution, please let me know. Thank you in advance!

agamesh
  • 559
  • 1
  • 10
  • 26
user2170248
  • 63
  • 1
  • 1
  • 5

2 Answers2

0

use ggplot::facet_grid to share the axis and gridExtra::grid.arrange to plot them side by side

data(mtcars)
require(ggplot2)
require(gridExtra)

p1 <- ggplot(mtcars, aes(x = factor(vs), y = mpg)) + 
  geom_boxplot() +
  facet_grid(cyl~.)

# Hope that i understood your question about the legend correctly

p2 <- ggplot(mtcars, aes(x = gear, y = mpg, col = factor(vs))) +
  geom_point() +
  facet_grid(cyl~.)

grid.arrange(p1,p2, nrow=1)

enter image description here

Rentrop
  • 20,979
  • 10
  • 72
  • 100
  • Thank you for answering. This is sort of what I mean, but I forgot to mention that my data.table is a little more complicated. The three graphs each have their own column with their data points, not one shared column like cyl. Should I put all the results below eachother and give them another factor (for instance cyl 4,6,8) to be able to do this? – user2170248 Dec 08 '14 at 12:17
  • have a look at `reshape2::melt` to arrange the data accodringly – Rentrop Dec 08 '14 at 12:18
0

enter image description here

This is how far I got this time. The figure are indeed similar within each row. However, I would like all the six graphs to be the same size, but it is difficult due to fact that the left 3 need a legend and "long" x-axis labels. The right panel is just the way I would like it for both panels and with that the x-labels and legend outside of the box.

For example the graph below with the legend (pasted on the right side) and x-labels added to it, without changing the figures size or at least cause no differences between figure sizes enter image description here

user2170248
  • 63
  • 1
  • 1
  • 5
  • Have a look here: http://stackoverflow.com/questions/13649473/add-a-common-legend-for-combined-ggplots – Rentrop Dec 11 '14 at 14:57