#1.Script to open required libraries library(bear) # loads bear package that is used to summarize data library(ggplot2) # loads ggplot2 package that is used to generate graphs library(Rcmdr) # loads RCommander package, which is the graphical user interface (GUI) #2. Script to summarize data summary <- summarySE(enzyme, measurevar="time", groupvars=c("ph")) summary # the term data is used to identify and refer to the summary you generated # summarySE is the command to summarize the data set enzyme # "enzyme" is the name you assigned to the data set, measurevar defines your response variable, and groupvars defines your dependemt variable. # graph will display your summary in the output window #3. Script to constrcut a line plot with error bars ggplot(data=summary, aes(x=ph, y=time)) + # data=indicates the data set, x=concentration is the x-variable and y=time1 is the y-variable geom_line(size=0.8) + # command to construct a line plot with line size=0.8 geom_point(size=2.5) + # command to add a symbol with a symbol size of 2.5 geom_errorbar(aes(ymin=time-se, ymax=time+se), size=1, width=.1) + # command to add errors that represent plus/minus 1 standard error xlab("pH") + ylab("Reaction rate (seconds)") + # command to add x-axis and y-axis labels scale_y_reverse(limits=c(60, 0), # scale_y_reverse sets a reversed range of the y-axis between the values indicated in the parenthesis breaks=seq(0,60,5)) + # Adjusts the axis ticks from 60 to 0 with 5 unit intervals theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), # removes default x-axis and y-axis grids panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text.y = element_text(size = 12, colour="black"), # sets y-axis text size and colour axis.text.x = element_text(size = 12, colour="black"), # sets x-axis text size and colour axis.title.y=element_text(size=14,face="bold", vjust=1.5), # sets y-axis label text size and position axis.title.x=element_text(size=14,face="bold", vjust=-.5))+ # # sets x-axis label text size and position ggtitle("pH") # Adds a plot title #4. Script to create a line plot with multiple lines #LINEPLOT FUNCTION plot(chlorophylla~wavelength, data=pigment, type="l", lty=1, lwd=2, # Plot command to make a line plot for one X-Y variable col="green", xlab="x-axis label", ylab="y-axis label", ylim=c(-0.1,2)) #5 ADD ADDITIONAL LINES lines(chlorophyllb~wavelength, data=pigment, type="l", lty=1, lwd=2, # Adds a second line col="blue") lines(xanthophyll~wavelength, data=pigment, type="l", lty=1, lwd=2, # Adds a third line col="yellow") lines(carotene~wavelength, data=pigment, type="l", lty=1, lwd=2, # Adds a fourth line col="orange") lines(total~wavelength, data=pigment, type="l", lty=1, lwd=2, # Adds a fifth line col="black") #6ADD A LEGEND legend("top", c("Chl-a","Chl-b","Xanthophyll","Carotene", "Total pigment"), # Adds a legend to the plot lty=c(1,1,1,1,1,1), # Assigns a line for the legend symbol lwd=c(2.5,2.5,2.5,2.5,2.5),col=c("green","blue","yellow","orange","black")) # Assigns line width and color #Script to construct an X-Y-Z plot #7. Script to load data for XYZ plot contruction data<-read.table("c:\\user\\Desktop\\xyz.txt",header=T) # this command loads the data set and associates it with the name "data". # the location of "user" may need to be changed, depending on how user is defined. attach(data) # Attach commands allow you to call the variables by name. names(data) # Names lists the variables you have assigned to the name data. #8. Script to interpolate data library(akima) # This opens the package graph <-interp(distance,depth,temperature) # this will interpolate X (distance), Y (temperature), and Z (temperature) to "fill" in data between know data points. #9 Script to generate a filled contour plot filled.contour(graph,col = colorRampPalette(c("blue", "yellow", "orange", "red"))(27), main = "Temperature",xlab="Distance (km)",ylab="Depth (m)", font.lab=2,ylim=rev(range(depth)), key.title = title(main=expression(~degree~C))) # this will produce a contour plot with a scale bar. The number in parenthesis after colorRampPalette(c("yellow", "orange", "red")) determines the number of colors. If colors repeat, increase that number. To change the color scheme, replace "yellow", “orange” “red”, with “blue”, “green”, “red” or any color combination! # The command [ylim=rev(range(Depth))] reverses the y-axis so zero is on top.