ggplot reduce line weight in legend

Viewed 2431

I am trying to control a plot using ggplot2

Sample Script:

dat1 <- data.frame(
     sex = factor(c("Female","Female","Male","Male")),
     time = factor(c("Lunch","Dinner","Lunch","Dinner"), levels=c("Lunch","Dinner")),
     total_bill = c(13.53, 16.81, 16.24, 17.42)
)
p = ggplot(data=dat1, aes(x=sex, y=total_bill, group=time, shape=time, color=time)) + geom_line() + geom_point()

Now I want to control how the shape and line looks like in the legend. I want a bigger shape, and thin line in the legend. But I can not perform the both.

If I do,

p = p + guides(colour = guide_legend(override.aes = list(size=5)))

Both line and shape are thick, similar to Fig B.

If I do,

p = p + guides(colour = guide_legend(override.aes = list(size=5,linetype=0)))

Then shapes appear at correct size, but line disappears (Fig A). I tried something like this unsuccessfully.

p = p + guides(colour = guide_legend(override.aes = list(size=5,linetype=0.5)))

Example

How to achieve a big shape and thin line in the legend?

1 Answers
Related