[R-sig-teaching] Graph Two Series over Time

Steven Stoline sstoline at gmail.com
Thu Dec 24 13:51:24 CET 2015


Dear All:

I am trying to plot two series in one graph. But I have some difficulties
to set up the y-axis lim. Also, the second series is not correctly graphed.

*Here is what I tried to do:*


### Define 2 vectors

Well1<-c(0.005,0.005,0.004,0.006,0.004,0.009,0.017,0.045,0.05,0.07,0.12,0.10,0.20,0.25)
Well2<-c(0.10,0.12,0.125,0.107,0.099,0.11,0.13,0.109,0.10,0.115,0.14,0.17,0.11)

### Calculate range from 0 to max value of Well1 and Well2
### g_range <- range(0, Well1, Well2)

max_y <- max(Well1, Well2)

### Graph Groundwater Concentrations using y axis that ranges from 0 to max
### value in Well1 or Well2 vector.  Turn off axes and
### annotations (axis labels) so we can specify them yourself

plot(Well1, type="o", pch=c(0,0,15,15,0,15,15,15,15,15,15,15,15,15),
col="blue", ylim=c(0,max_y), axes=FALSE, ann=FALSE, , lwd=3, cex=1.25)  ###
axes=FALSE,

### Make x axis using Jan 2005 - Dec 2008 labels

axis(1, at=1:14,
lab=c("Jan05","April05","Jul05","Oct05","Jan06","March06","Jun06","2Oct06","17Oct06","Jan07","April07","Jul07","Oct07","Dec07"))



*### Make y axis with horizontal labels , Here what I have the major
problem*

### I want the y-axis looks like: 0, 0.05, 0.10, 0.15, 20, 0.25

axis(2, las=0, at=6*0:max_y)  ### max_y


### Create box around plot

box()

### Graph Well2 with red dashed line and square points

### lines(Well2, type="o", pch=22, lty=2, col="red", lwd=3, cex=1.0)

lines(Well2, type="o", pch=c(0,15,15,15,0,15,15,15,0,15,15,15,15), lty=2,
col="red", lwd=3, cex=1.25)

### Create a title with a red, bold/italic font

title(main="Trichloroethene mg/L from Wells 1 and 2 - 2005-2007",
col.main="red", font.main=2)

### Label the x and y axes with dark green text

title(xlab="Time Points", col.lab=rgb(0,0.5,0))


title(ylab="Trichloroethene mg/L", col.lab=rgb(0,0.5,0))

### Create a legend

legend(1, g_range[2], c("Well1","Well2"), cex=1.0, col=c("blue","red"),
pch=15:15, lty=1:2);




with thanks
steve
-------------------------
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
sstoline at gmail.com

	[[alternative HTML version deleted]]



More information about the R-sig-teaching mailing list