## 2-D Plotting # Read the data from a dat file. pd = read.table("../matlabdata.dat") # Basic plotting of y vs x dev.new() plot(pd[,1],pd[,2], xlab="x", ylab="y") dev.new() x1 = seq(-2*pi, 2*pi, 4*pi/1024) y1 = x1 * sin(x1^2) # now a better plot plot(x1,y1, type="l",xlab="x", ylab="f(x)", col="blue", main="Graph of f(x)=x sin(x^2)", lwd=2) grid(nx=NULL,ny=NULL, lty=2, lwd=1, col="gray60", equilogs=TRUE) # To save the plots png("r_fig_1.png") plot(pd[,1],pd[,2], xlab="x", ylab="y") dev.off() png("r_fig_2.png") plot(x1,y1, type="l",xlab="x", ylab="f(x)", col="blue", main="Graph of f(x)=x sin(x^2)", lwd=2) grid(nx=NULL,ny=NULL, lty=2, lwd=1, col="gray60", equilogs=TRUE) dev.off()