Sunday, October 3, 2010

Chart of different lty values in R

Here we can see the lty values available in R:
Only a few options, but using different colors and lwd sizes allows for many different options. Below is an example of how using different lty values helps distinguish between different types of data:
And the code:
plot(1, type="n", axes=F, xlab="", ylab="",xlim=c(0,10),ylim=c(0,20),
main="List of lty values in R",cex.main=2)
lines(c(0,10),c(17,17),lwd=2,lty=1)
text(2,16,'lty = 1 (default)',pos=4)
lines(c(0,10),c(14,14),lwd=2,lty=2)
text(2,13,"lty = 2  -or-  lty = 'dashed'",pos=4)
lines(c(0,10),c(11,11),lwd=2,lty=3)
text(2,10,"lty = 3  -or-  lty= 'dotted'",pos=4)
lines(c(0,10),c(8,8),lwd=2,lty=4)
text(2,7,"lty = 4",pos=4)
lines(c(0,12),c(5,5),lwd=2,lty=5)
text(2,4,"lty = 5",pos=4)
lines(c(0,10),c(2,2),lwd=2,lty=6)
text(2,1,"lty = 6",pos=4)

plot(1,type='n',axes=T,xlab='',ylab='',xlim=c(0,10),ylim=c(1,10),main='Plot of Highway Data',cex.main=2)
abline(3,.75,lwd=2)
abline(1,.75,lwd=3,lty='dashed',col='yellow2')
abline(-1,.75,lwd=2)
lines(c(4,5),c(5,5.75),lwd=25,col='grey')
points(3.7,4.7,bg='red',pch=23,cex=2.5)
lines(c(3,3.5),c(2.1,2.475),lwd=20,col='blue')
points(3.2,2.25,cex=2,pch=19,col='skyblue4')
lines(c(8,8.3),c(8.2,8.45),lwd=20,col='green4')
points(8.19,8.35,cex=2,pch=23,bg='green3',col='green4')


No comments:

Post a Comment