Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot black and white

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("")
like image 863
Donbeo Avatar asked Nov 21 '25 10:11

Donbeo


1 Answers

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

like image 66
Jonas Tundo Avatar answered Nov 23 '25 02:11

Jonas Tundo