Imagine I have a data matrix, my_matrix, that looks like this:
1 | 2 | 3 | |
---|---|---|---|
Sample A | 0.0001 | 0.0003 | 0.00035 |
Sample B | 0.0002 | 0.0001 | 0.00023 |
Sample C | 0.0000 | 0.0002 | 0.00046 |
On a single plot, I wanted to create a line for Sample A (connecting the values for variables 1, 2, and 3), a line for Sample B, and so on.
I melted the data and plotted it like so:
ggplot(data=melt(my_mtrx),
aes(x=Var2, y=value, colour=Var1)) +
geom_line() +
scale_color_manual(values = c(rep("green", 105)))
The issue I’m facing is that in the legend, ggplot creates an entry for each of Sample A, B, and C. But imagine that Sample A and C actually belong to one ‘group’, and C to another. So instead of a legend like this:
Sample A
Sample B
Sample C
I want a legend like this:
Group X
Group N
2