# Single Variable Arguments and Arguments to Plot Function # R Graphics seminar # 28 January 2013 #NJG #################################################### # Standard calls for preserving defaults, and reading a csv opar <- par(no.readonly=TRUE) Ant.Data <- read.csv("antcountydata.csv",header=TRUE) attach(Ant.Data) #################################################### # illustrating plots for a single dimension of data plot(n.species) # plots numeric data in order plot(ecoregion) # plots counts of factors as bars plot(table(ecoregion)) # plots tabled counts of factors as lines barplot(ecoregion) #errror b/c barplots wants a numeric, not a factor Little.Data <- c(3,2,1,5,6) Little.Data.Labels <- c("A", "B", "Cc","Ddd","E") barplot(Little.Data,names.arg=Little.Data.Labels) # plots numeric data as bar heights pie(Little.Data, labels=Little.Data.Labels) # plots numeric data as pie slices dotchart(Little.Data,labels=Little.Data.Labels) # plots numeric data as ordered dot plots boxplot(n.species) # plots numeric data as box plot hist(n.species) # plots numeric data as histogram stripchart(Little.Data) # plots numeric data in a single strip chart plot(density(n.species)) # plots kernel density of a numeric variable #################################################### # illustrating panel layout and 6 variations on plot type Random.Data <- rnorm(20) par(mfrow=c(3,2)) plot(Random.Data,type="p") plot(Random.Data,type="l") plot(Random.Data,type="b") plot(Random.Data,type="o") plot(Random.Data,type="s") plot(Random.Data,type="h") par(opar) plot(Random.Data,type="n") plot(Random.Data,ann=FALSE) plot(Random.Data,axes=FALSE) plot(Random.Data,ann=FALSE, axes=FALSE) #################################### # Set the data limits, plot limits, box plot(Random.Data,xlim=c(0,30),ylim=c(-2,4)) par(pty="m") plot(Random.Data) # default is "m" par(opar) par(pty="s") plot(Random.Data) par(opar) plot(Random.Data,bty="o") plot(Random.Data,bty="n") plot(Random.Data,bty="l") plot(Random.Data,bty="7") plot(Random.Data,bty="]") plot(Random.Data,bty="c") plot(Random.Data,bty="u") #################################################### #Illustrating size, color, and shape of points # pch 1-20 single color; 21-25 two colors with bg # Use "." for a pixel and "A" for a character plot(Random.Data,type="b", cex=3, pch=24, col="blue", bg="gold") # Illustrating thickness, color, and type of lines plot(Random.Data,type="b", cex=3, pch=24, col="black", bg="gold", lwd = 2, lty="twodash") # 2 4 6 or 8 digit hex string plot (lat.centroid,n.species,pch=1,cex=n.samples) ########################################################## # Arguments for axis labels # Illustrating axes and title labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title") # Illustrating colors for labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title", col.axis="red", col.lab="blue", col.main="orange", col.sub="green") # Illustrating font styles for labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title", font.axis=1, # 1 = plain text font.lab= 2, # 2 = bold font.main=3, # 3 = italic font.sub=4) # 4 = bold italic # Illustrating font families for labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title", font.axis=1, font.lab= 1, font.main=1, font.sub=1, family="sans") # base families sans,serif,mono # Illustrating sizes for labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title", cex.axis=2, cex.lab= 1, cex.main=3, cex.sub=0.75) # Illustrating orientation for axis labels plot(Random.Data, xlab="X axis label", ylab="Y axis label", main="Main Title", sub="Sub Title", las = 1) # 0=parallel, 1= horiz 2=perp 3=vert detach(Ant.Data) # detach ant data par(opar) # restore original parameters ls() # list objects in memory rm("lbls") # remove a single object from memory rm(list=ls()) # remove all objects from memory - optional!