<several line graphs in a graph>
> ggplot(data=T,aes(x))+geom_line(aes(y=df_1))+geom_line(aes(y=df_5))+geom_line(aes(y=df_20))+geom_line(aes(y=dnorm(x,0,1)))
<Color each line graphs>
> ggplot(data=T,aes(x))+geom_line(aes(y=df_1),col="red")+geom_line(aes(y=df_5),col="blue")+geom_line(aes(y=df_20),col="yellow")+geom_line(aes(y=dnorm(x,0,1)))
<Change the title, the name of labs of the graph>
>
ggplot(data=T,aes(x))+geom_line(aes(y=df_1,col="df_1"))+geom_line(aes(y=df_5,col="df_5"))+geom_line(aes(y=df_20,col="df_20"))+geom_line(aes(y=dnorm(x,0,1),col="norm"))+labs(y="density",title="Tdistribution")+scale_colour_manual(values=c("df_1"="red","df_5"="blue","df_20"="yellow","norm"="black"))
<Add colors to each geom_line() with legend>
You should recognize that col="" be included in aes() which is the difference with the example above.
> ggplot(data=T,aes(x))+geom_line(aes(y=df_1,col="df_1"))+geom_line(aes(y=df_5,col="df_5"))+geom_line(aes(y=df_20,col="df_20"))+geom_line(aes(y=dnorm(x,0,1),col="norm"))+labs(y="density",title="Tdistribution")+scale_colour_manual(values=c("df_1"="red","df_5"="blue","df_20"="yellow","norm"="black"))
<Change the order of legend>
> ggplot(data=T,aes(x))+geom_line(aes(y=df_1,col="df_1"))+geom_line(aes(y=df_5,col="df_5"))+geom_line(aes(y=df_20,col="df_20"))+geom_line(aes(y=dnorm(x,0,1),col="norm"))+labs(y="density",title="Tdistribution")+scale_colour_manual(values=c("df_1"="red","df_5"="blue","df_20"="yellow","norm"="black"),breaks=c("df_1","df_5","df_20","norm"))
'R' 카테고리의 다른 글
(R) Two sample Bootstrap Method (0) | 2020.10.23 |
---|---|
(R) One-sample Bootstrap Method (0) | 2020.10.17 |
(R) Central limit theorem (0) | 2020.09.27 |
(R) Normal approximation to Binomial (0) | 2020.09.27 |
(R) geom_violin() - a density graph (0) | 2020.09.09 |