# [R] creating multiple line graphs

Jim Lemon jim at bitwrit.com.au
Tue Apr 15 08:33:52 CEST 2014

```On 04/15/2014 12:27 PM, dila radi wrote:
> Hi all,
>
> I tried to draw multiple line graphs, and this is my data:
>
> structure(list(X = structure(c(3L, 1L, 2L), .Label = c("10%",
> "20%", "5%"), class = "factor"), NRM = c(0.993112, 0.9757191,
> 0.9709928), AAM = c(0.9928504, 0.9764055, 0.9702813), IDW = c(0.9923301,
> 0.9737133, 0.9640287), CCM = c(0.9929805, 0.9768217, 0.9708724
> ), MI = c(0.9931722, 0.9715817, 0.9649249)), .Names = c("X",
> "NRM", "AAM", "IDW", "CCM", "MI"), row.names = c(NA, 3L), class =
> "data.frame")
>
>
> Im using these as my codes:
> y-axis is the amount of S-index (from the data given range from 0.99 - 1.0)
> x-axis is the percentage (5%, 10% and 20%)
>
> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0))
> plot(dt[,2], xaxt = "n",xlab="Percentage of Mising",ylab="S-index",
>       main="Performance of S-Index for Different Percentage",
>       ylim=c(0.99,1),type="l",col="blue",lwd=3)
> lines(dt[,3],col="black",lwd=3,lty=2)
> lines(dt[,4],col="red",lwd=3,type="l")
> lines(dt[,5],col="green3",lwd=3,type="l")
> lines(dt[,6],col="orange",lwd=3,lty=2)
> axis(1,at=1:3,c("5%","10%", "20%"))
> legend("topright", bty="n",c("NRM","AAM","IDW","CCM","MI"),
> lwd=c(3,3,3,3,3), lty =c(1,2,1,4),col=
> c("blue","black","green3","red","orange"))
>
> I guess there is more sophisticated way to do it. Need your help. Thank you
> so much.
>
Hi Dila,
Try this:

matplot(as.matrix(dt[,2:6]),type="b",
col=c("blue","black","green3","red","orange"),
pch=c("N","A","I","C","M"),lty=1:5,lwd=2)
legend("topright", bty="n",c("NRM","AAM","IDW","CCM","MI"),
lty=1:5,col=c("blue","black","green3","red","orange"),
pch=c("N","A","I","C","M"),lwd=2)

Jim

```