[R] plot with 2 y axes

kirtau kirtau at live.com
Wed Jan 26 17:19:49 CET 2011


I hope this is what you are looking for. you will have to add your own colors
and such.

year = c(1966:2008)
tempur =
c(2.9,4.5,1.9,1,2.9,4.3,3.9,4.3,4.9,4.4,4.5,2,2.8,-.4,2.3,3,.3,1.7,3.3,.8,-1.1,.8,4.9,5.2,4.9,1.5,3.7,3.6,3.2,4.8,2.3,2.5,5.2,5.3,4.9,3.2,3.6,3.9,4.8,4.3,3.7,5.8,4.9)
indx =
c(1,1.24,1.46,1.37,1.87,2.66,3.07,3.91,4.16,4.32,2.52,2.44,2.18,1.18,1.93,2.13,1.92,2.24,2.01,1.89,.66,1.01,1.5,2.11,2.02,.7,.75,1.28,1.37,2.01,1.54,2,2.07,2.11,2.42,2.29,2.15,2.21,2.14,2.33,1.89,2.03,2.58)
data1 = data.frame(year,tempur,indx)

# create new graphing window
windows()
# create margins for variable names
par(mar = c(5,5,5,5))
# create bar plot
barplot(data1$tempur, names = data1$year, xlab = "year", ylab = "Temp")
# Allows for plotting on same charts (kinda like overlay)
par(new=T)
# plot line points
plot(data1$year,data1$indx, xaxt = "n", yaxt = "n", xlab = "", ylab = "")
# add lines
lines(data1$year,data1$indx)
# adds axis for second plot to right hand side
axis(side = 4)
# adds second y axis variable name to right hand side
mtext("Index",side = 4, line = 3)
# quits plotting on the current plotting window
par(new = F)
-- 
View this message in context: http://r.789695.n4.nabble.com/plot-with-2-y-axes-tp3237418p3238368.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list