ggplot黑色和白色

Don*_*beo 3 graphics r ggplot2

我有一个用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("")
Run Code Online (Sandbox Code Playgroud)

结果很好 在此输入图像描述

不太可能我必须用黑白打印.什么是最好的事情?是否有任何选项可以优化黑白版本的颜色?

这里有一个可重复的例子

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("")
Run Code Online (Sandbox Code Playgroud)

JT8*_*T85 6

您的y值应该在一个变量中,该变量对应于此示例中的变量Species.例如:

更改线型:

ggplot(iris)  + 
  geom_line(aes(Sepal.Length,Petal.Length,linetype=Species)) +
  theme_classic()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

要么

更改线型和点形状:

ggplot(iris)  + 
  geom_line(aes(Sepal.Length,Petal.Length,linetype=Species)) + 
  geom_point(aes(Sepal.Length,Petal.Length,shape=Species)) +
  theme_classic()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述