[R] Legend formatting (ggplot2)

Robert Lynch robert.b.lynch at gmail.com
Wed Aug 28 23:09:54 CEST 2013


I am having trouble getting my legend to format the way I want it to.  I
suspect it is something simple.

>
> the code I have is
> library(ggplot2)
> ggplot(Chem.comp, aes(Course, GRADE.)) + geom_boxplot(notch =
> TRUE,aes(fill = COHORT))+
>   labs(title = "Comparison between ISE cohorts and Peers in the Same Chem
> 2 class",
>        y ="Grade Points in class",
>        x = "Chemistry 2 quarter") + ylim(0,4.3333)+guides(colour =
> guide_legend(nrow = 3))+
>   scale_fill_manual(name = "ISE Cohorts &\nComparison groups", values =
> c("blue","red","blue3","red3","blue4","red4"))
>
> which plots as attached
>
> I would like to have the legend as two columns one blue (ISE07, ISE08,
> ISE09) and one red ( Comparison 07, Comparison 08, Comparison 09)
>
> the guids(colour = guide_legend(nrow=3)) is what I found at stack overflow
>


> (
> http://stackoverflow.com/questions/12323416/arranging-ggplot2-legend-items-in-a-grid
> )
>  and I am not quite sure how to parse for myself the ggplot documentation
> page but it looks the same.
>
http://docs.ggplot2.org/current/guide_legend.html

>
> Ideally I'd like the legend to have a column of text lables,(ISE...) a
> column of blue boxes, a column of red boxes and a column of text labels
> (Comp....). but that is mostly just bonus.
>
> Thanks
> Robert
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1ColLedgend.pdf
Type: application/pdf
Size: 7418 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130828/021329bd/attachment.pdf>


More information about the R-help mailing list