Jacqueline Nolis
Jacqueline Nolis

Reputation: 1547

A tree of plots in ggplot2

I have a collection of data that is hierarchical in nature, forming groups that would each be best plotted as a bar chart. If it's possible, I would love to be able to arrange a bunch of ggplot2 graphs so that they form a tree structure: bar plots forming a tree

Is this something you can do with ggplot2 or supplemental package? The patchwork package seems to be the closest but doesn't allow that amount of flexibility in positioning.

Thanks!

Upvotes: 3

Views: 276

Answers (1)

claudius
claudius

Reputation: 1005

You could use a combination of packages gridExtra and ggplot2. To know more details I recommander look these vignettes: Laying out multiple plots on a page and Arranging multiple grobs on a page.

require(gridExtra)
require(ggplot2)

layout <- rbind(c(NA,1,1,NA),
              c(2,2,3,3))

p <- qplot(1,1)
p2 <- qplot(2,4)
p3 <- qplot(3,1)

grid.arrange(p, p2, p3,  layout_matrix=layout)


Example

Upvotes: 1

Related Questions