[R] Legend formatting (ggplot2)

Ista Zahn istazahn at gmail.com
Thu Aug 29 00:56:06 CEST 2013


Hi Robert,

Your legend is for fill, not color, so you need

guides(fill = guide_legend(nrow = 3))

instead of

guides(colour = guide_legend(nrow = 3))

Best,
Ista

On Wed, Aug 28, 2013 at 5:09 PM, Robert Lynch <robert.b.lynch at gmail.com> wrote:
> 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
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list