Skip to content

multiple plots - editing ggplot2 plot

3 messages · Pedro Barros, Hadley Wickham

#
Hi All,

I am trying to build a composite plot, with multiple categories, using
ggplot2.

In principle, it could be done using facetting, but I do not seem to be able
to get past the defaults, so I try building each plot separately, then
putting them all together using frameGrob and placeGrob.
For this, I need to know how to:
1) format the legend with a different layout (e.g 2 rows by 2 columns,
rather than using the vertical orientation only;
2) draw the numbers on top of the bars (the issue is locating the bars, of
course);
3) extract the definition of the axes (scales, with breaks and labels) from
the individual plots

I am attaching an image describing what I would like to achieve. The quality
is low, to avoid consuming too much of your bandwidth.
I would appreciate any pointers.
Thanks,
Pedro http://www.nabble.com/file/p19703615/MultiPlotDesign.jpg
MultiPlotDesign.jpg
2 days later
#
On Sat, Sep 27, 2008 at 10:20 AM, Pedro Barros <pedro.barros at fao.org> wrote:
Could you post the data that you are using?  You should be able to do
most of that without any customisation of ggplot2.

Hadley
#
Hi Hadley,

Thanks for the quick reply.
Well, if I could do it directly in ggplot, even better.
My data is below (from "dump").
I calculate the bar heights previously, now I just want to plot them, with
fixed fill colours (to make sure they match other plots I use). Thanks
again,
Pedro

`x1` <-
structure(list(Facets = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("10-", 
"20-", "30-", ">40"), class = c("ordered", "factor")), Bars =
structure(c(2L, 
2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L), .Label = c("South", "North"), class = c("ordered", 
"factor")), BarClasses = structure(c(3L, 5L, 3L, 5L, 1L, 3L, 
5L, 3L, 5L, 1L, 3L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 3L, 5L), .Label =
c("Cephalopods", 
"Euphausiacea", "Fish", "Polychaetes", "Shrimps"), class = "factor"), 
    BarHeights = structure(c(0.997020854021847, 0.00297914597815293, 
    0.775862068965517, 0.224137931034483, 0.00023335127316569, 
    0.985671202336716, 0.0140954463901187, 0.341701062318154, 
    0.658298937681846, 1.91509512799799e-05, 0.803486865929413, 
    0.196493983119307, 0.0755241837337877, 0.00347717236343406, 
    0.423797767655343, 0.00066066274905247, 0.496540213498383, 
    0.165470521161714, 0.654638138037427, 0.179891340800859), .Dim = 20L,
.Dimnames = list(
        c("Cephalopods", "Cephalopods", "Cephalopods", "Cephalopods", 
        "Cephalopods", "Cephalopods", "Cephalopods", "Cephalopods", 
        "Cephalopods", "Cephalopods", "Cephalopods", "Cephalopods", 
        "Cephalopods", "Cephalopods", "Cephalopods", "Cephalopods", 
        "Cephalopods", "Cephalopods", "Cephalopods", "Cephalopods"
        )))), .Names = c("Facets", "Bars", "BarClasses", "BarHeights"
), class = "data.frame", row.names = c(NA, -20L))
hadley wrote: