I am trying to plot a group of lines and assign one label to these lines in the legend. Here's an example of the data (df2) that I am using.
structure(list(
true = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("model1", "model2"), class = "factor"),
test = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L),
.Label = c("false.model1", "false.model2", "false.model3", "true model"), class = "factor"),
est.interval = c(0, 5, 5, 7, 7, 10, 10, 11, 11, 0, 2, 2, 3, 3, 0, 2, 2, 4, 4, 0, 2, 2, 3, 3, 4, 4, 0, 7, 7, 10, 10, 13, 13, 0, 4, 4, 5, 5, 0, 5, 5, 6, 6, 7, 7, 9, 9, 0, 2, 2, 3, 3, 4, 4),
sens = c(1, 1, 0.75, 0.75, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.75, 0.75, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0, 1, 1, 0.75, 0.75, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0)),
.Names = c("true", "test", "est.interval", "sens"),
class = "data.frame")
And here I plot the curves using ggplot.
ggplot(df2, aes(x=est.interval, y=sens, color=test)) +
ylim(0,1) +
geom_line(size = 0.6) +
facet_wrap(~true, nrow=1) +
scale_colour_manual(values=c(rep('#CCCCCC', 3), "#000000"), name="Estimation Model") +
guides(color=guide_legend(keywidth = 3, keyheight = 1))
I'd like to have the three grey "false.model" curves separately visible on the plot, but in the legend I just want one "false models" entry beside one grey line. Any thoughts on how to do this?
true.models.testCase
in order to be runnable, plus the spaces in your data.values makes this very difficult to import into R via copy/paste. It would be better to include adput()
of your sample data. Even better just give usdf2
and that's what you want to plot. How you create that data is really irrelevant. Without having the code to generate the plot as you see it, it's difficult to offer suggestions. – MrFlick