3

I have a plot obtained with ggplot2

ggplot()+geom_line(data=results,aes(x=SNR,y=MeanLambdaMin,group=rep),col="blue")+
  geom_line(data=results,aes(x=SNR,y=MeanA,group=rep),col="green")+
geom_line(data=results,aes(x=SNR,y=VarA,group=rep),col="red")+
  geom_line(data=results,aes(x=SNR,y=VarB,group=rep),col="black")+
facet_wrap(~ rep, as.table=T)+xlab("SNR")+ylab("")

The result is good enter image description here

Unlikely I have to print it in black and white. What is the best thing to do? Is there any option which optimize the color for a black and white versione?

here there is a reproducible example

results=data.frame("SNR"=1:30)
results$MeanA=results$SNR^2
results$VarA=results$SNR*2
results$VarB=results$SNR^(1/2)
results$MeanLambdaMin=1:30
results$rep=sample(x=1:3,size=30,replace=T)

ggplot()+geom_line(data=results,aes(x=SNR,y=MeanLambdaMin,group=rep),col="blue")+
  geom_line(data=results,aes(x=SNR,y=MeanA,group=rep),col="green")+
geom_line(data=results,aes(x=SNR,y=VarA,group=rep),col="red")+
  geom_line(data=results,aes(x=SNR,y=VarB,group=rep),col="black")+
facet_wrap(~ rep, as.table=T)+xlab("SNR")+ylab("")
plannapus
  • 18,529
  • 4
  • 72
  • 94
Donbeo
  • 17,067
  • 37
  • 114
  • 188
  • 3
    Can you give a reproducible example? You should map color, line type, point type, to a variable and call it through an aesthetic. – Roman Luštrik Jun 19 '13 at 09:27
  • use gray-black scaling – Sander Van der Zeeuw Jun 19 '13 at 09:33
  • Can you please write the code. I am not expert with ggplot2. – Donbeo Jun 19 '13 at 09:39
  • @Donbeo You were asked to provide a reproducible example but then asekd a question instead of adding the reproducible example. I assume that you may not know what that is. [Here](http://stackoverflow.com/q/5963269/1000343) is info on doing so. Basically if we don't have data to run it makes helping much more difficult and it makes understanding the solution more difficult. – Tyler Rinker Jun 19 '13 at 12:00

2 Answers2

7

Your y values should be in one variable that correspond to the variable Species in this example. For instance:

Change linetype:

ggplot(iris)  + 
  geom_line(aes(Sepal.Length,Petal.Length,linetype=Species)) +
  theme_classic()

enter image description here

or

Change linetype and shape of points:

ggplot(iris)  + 
  geom_line(aes(Sepal.Length,Petal.Length,linetype=Species)) + 
  geom_point(aes(Sepal.Length,Petal.Length,shape=Species)) +
  theme_classic()

enter image description here

Roland
  • 127,288
  • 10
  • 191
  • 288
Jonas Tundo
  • 6,137
  • 2
  • 35
  • 45
  • +1 - you could also vary the line width (good for if you want to highlight one line over others), and with only 3 you it wouldn't be impossible to construct three visibly distinct grey scales. Adding the points allows more areal gurth the distinguish different colors on the grey scale as well. – Andy W Jun 19 '13 at 13:05
0
ggplot() +
  geom_line(data=results,aes(x=SNR,y=MeanLambdaMin,group=rep),col="grey0") +
  geom_line(data=results,aes(x=SNR,y=MeanA,group=rep),col="grey20") +
  geom_line(data=results,aes(x=SNR,y=VarA,group=rep),col="grey40") +
  geom_line(data=results,aes(x=SNR,y=VarB,group=rep),col="grey80") + 
  facet_wrap(~ rep, as.table=T) +
  xlab("SNR") +
  ylab("")

Now you have differences in black and white scaling :) play with the colors to look for the best combinations. You can see all colors by entering 'colours()'

also you can add + theme_grey() at the end of your plot code

hugomg
  • 68,213
  • 24
  • 160
  • 246
Sander Van der Zeeuw
  • 1,092
  • 1
  • 13
  • 35