alter legend colour

15 views
Skip to first unread message

Martin Kärcher

unread,
Jul 31, 2010, 5:43:08 AM7/31/10
to ggplot2

Dear all,


I have attached a graph where it is almost impossible to see the colour of the legend. For some reason there is a white mist over the colours which I'd prefer not to have. Also, how can I make the pink and turquoise lines of the legend more visible, e.g. how can I make the lines thicker?


I've also tried to find out how to change the colours of the bars but was unable to change the line and the fill at the same time. With e.g. “scale_colour_manual(values = c("#colour", "#colour")” I only managed to change the lines but not the fill. Can you please suggest me an approach for this problem as well?


This time I've attached the script, the dataset, and the PDF of the graph.


Many thanks and best wishes,


Martin


p.s.: dput(df) returns:


structure(list(trt = structure(c(2L, 1L, 2L, 1L), .Label = c("female",

"male"), class = "factor"), resp = c(39.8991596638655, 45.6,

36.4324324324324, 41.0709677419355), group = structure(c(2L,

2L, 1L, 1L), .Label = c("A. m. carnica", "A. m. mellifera"), class = "factor"),

se = c(2.2914511080157, 4.22612618460644, 0.301499108660928,

2.81161238668346)), .Names = c("trt", "resp", "group", "se"

), row.names = c(NA, -4L), class = "data.frame")



 

Martin H. Kärcher

Laboratory of Apiculture & Social Insects

Department of Biology & Environmental Science

School of Life Sciences

John Maynard Smith Building

University of Sussex

Brighton BN1 9QG, UK


landline (Austria): +43 316 382448

mobile (Austria): +43 650 3824481

landline (England): +44 127 387 7198

http://www.sussex.ac.uk/biology/profile220918.html



B.plot2.pdf
exp2.foR.h.csv
graph_2

Dennis Murphy

unread,
Jul 31, 2010, 9:37:25 AM7/31/10
to Martin Kärcher, ggplot2
Hi:

I have to admit that I'm not a big fan of stacking, so I modified your plot call to place the crossbars side-by-side (using position_dodge) and included a call to scale_fill_manual() to do the alpha transparency. I think it's easier to read, but it's one person's opinion.  Here's my modified code:

df <- structure(list(trt = structure(c(2L, 1L, 2L, 1L), .Label = c("female",
"male"), class = "factor"), resp = c(39.8991596638655, 45.6,
36.4324324324324, 41.0709677419355), group = structure(c(2L,
2L, 1L, 1L), .Label = c("A. m. carnica", "A. m. mellifera"), class = "factor"),
    se = c(2.2914511080157, 4.22612618460644, 0.301499108660928,
    2.81161238668346)), .Names = c("trt", "resp", "group", "se"
), row.names = c(NA, -4L), class = "data.frame")

ggplot(df, aes(fill = group, colour = group, y = resp, x = trt)) +
    geom_crossbar(limits, width = 0.5, position = position_dodge(width = 0.6)) +
    opts(legend.position = c(0.77, 0.89), legend.background = theme_rect(colour = 0)) +
    opts(legend.text = theme_text(face = "italic", size = 17)) +
    opts(legend.title = theme_blank()) +
    scale_fill_manual(values = alpha(c('red', 'green'), 0.2)) +
    labs(x = "sex", y = "time to be replaced [h]\n") +
    opts(axis.text.x = theme_text(size = 15, vjust = 1),
             axis.text.y = theme_text(size = 15, hjust = 1)) +
    opts(axis.title.x = theme_text(size = 25, hjust = 0.535),
             axis.title.y = theme_text(size = 25, angle = 90, vjust = 0.67, hjust = 0.78))

The changes are in line 2 (adding a position = statement) and in line 6 (addition of scale_fill_manual()).

The scale_fill_manual() code should answer the questions about color choice and alpha transparency not leaking to the legend, but I couldn't figure out how to control the line thickness in the legend (a very good question, BTW). I'm interested in knowing how this works, too.

HTH,
Dennis


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Hadley Wickham

unread,
Jul 31, 2010, 9:50:01 AM7/31/10
to Dennis Murphy, Martin Kärcher, ggplot2
> The scale_fill_manual() code should answer the questions about color choice
> and alpha transparency not leaking to the legend, but I couldn't figure out
> how to control the line thickness in the legend (a very good question, BTW).
> I'm interested in knowing how this works, too.

Currently there's no way to control it - and I'm not sure what the
syntax would look like for specifying some aesthetic choices and
leaving the rest automatic.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages