I have the following plot in ggplot2
(made-up modification of the ChickWeight dataframe):
require(ggplot2)
ChickWt <- data.frame(ChickWeight, Sex = rep(c("M", "F"), times = 289))
p1 <- ggplot(ChickWt, aes(x=Time, y=weight,
colour=Diet, Group = Chick, linetype = Sex)) + geom_line()
p1
which yields the following:
This is fine, except for the legend.
I would like the legend to be of four pairs:
Diet 1-M (colored Purple, solid line), Diet 1-F (colored Purple, brokem line),
Diet 2-M (colored Green, solid line), Diet 2-F (colored Green, brokem line), ....
and so on. Let us say I would like to put the labels in a 2x2 block. I believe that I can put the labels in a 2x2 block using
p1 + guides(fill=guide_legend(nrow = 2, ncol = 2))
but the question I am stumped on is how to make the legend for the four pairs of diet-gender combinations. Any suggestions would be a great help!