KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm struggling a great deal to modify the legend in my plot. Here is a reproducible example: dtt <- structure(list(model = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("ma", "mb", "mc"), class = "factor"), year = c(2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L), V = c(0.16, 0.14, 0.11, 0.13, 0.15, 0.16, 0.24, 0.17, 0.12, 0.13, 0.15, 0.15, 0.2, 0.16, 0.11, 0.12, 0.12, 0.15), lower = c(0.11, 0.11, 0.07, 0.09, 0.11, 0.12, 0.16, 0.12, 0.04, 0.09, 0.09, 0.11, 0.14, 0.1, 0.07, 0.08, 0.05, 0.1), upper = c(0.21, 0.19, 0.17, 0.17, 0.19, 0.2, 0.29, 0.23, 0.16, 0.17, 0.16, 0.2, 0.26, 0.27, 0.15, 0.16, 0.15, 0.19)), .Names = c("model", "year", "V", "lower", "upper"), class = "data.frame", row.names = c(NA, -18L)) My plot is generated like this: ggplot(dtt, aes(x=year, y=V, group = model, colour = model, ymin = lower, ymax = upper)) + geom_ribbon(alpha = 0.35, linetype=0)+ geom_line(aes(linetype=model), size = 1.5) + geom_point(aes(shape=model), fill = "white", size = 4) + theme(legend.position=c(.6,0.8)) + theme(legend.background = element_rect(colour = 'black', fill = 'grey90', size = 1, linetype='solid')) which produces this: Now, what I would like to do is change the title of the legend change the order in which the legend items appear change the text of the legend items. I have fiddled around for hours trying to do this, but without much success. The best I have managed so far is to add this: scale_colour_hue(name = "Model 1", breaks=c("mb", "ma", "mc"), labels=c("MBB", "MAA", "MCC")) But it produces this abomination: <img src="https://i.sstatic.net/je9Bi.png" alt="e
Tags (comma-separated)
Save Edits
Cancel