0

I used melt so that I could easily display several lines on the same graph using ggplot2. However, this only really works when I have the color set to variable. When I try to change it to black or any other color I get this unfortunate pattern. I am sure this is a quick fix but I can't figure it out

df.melted <- melt(john, id = "sample_size")
GRAPH<-ggplot(data = df.melted, aes(x = sample_size, y = value, color = variable))+
  geom_line()+theme_classic()+coord_cartesian(xlim = c(0,100))+theme(legend.position="none")+

The resulting graph is here... enter image description here

And when I try to change set the color = "black" in either aes() or geom_line() I get these red lines:

enter image description here

tonytonov
  • 25,060
  • 16
  • 82
  • 98
Tom G
  • 1
  • 2
  • Welcome to SO! Please take a look at [how to make reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In your case, you can set color with e.g. `scale_colour_discrete`. – tonytonov Apr 20 '16 at 12:14
  • 5
    try replacing colour with group in the aes() – Richard Telford Apr 20 '16 at 12:17
  • `color="black"` inside `aes` is treated like a new factor column of data that takes on only one value, "black", and is mapped to a single default color (because there's only one factor level) by ggplot, which happens to be red. You could replace "black" with anything and the result would be the same. Try these, for example, `ggplot(mtcars, aes(wt, mpg, colour="black")) + geom_line()` or `ggplot(mtcars, aes(wt, mpg, colour="mimsy")) + geom_line()`. But this will give you black: `ggplot(mtcars, aes(wt, mpg)) + geom_line(color="black")` (black is the default, so you don't really need to set it). – eipi10 Apr 20 '16 at 14:35
  • 1
    Also, in your case, as @RichardTelford said, you need `group=variable` inside `aes` in order to get separate lines for each value of variable. – eipi10 Apr 20 '16 at 14:37
  • Thanks...switching group and color worked perfectly! Thanks a bunch! – Tom G Apr 20 '16 at 16:23

0 Answers0