Dear all,
I am trying to plot some data with differing range in y-values with
type="b", adding error bars and break the y-axis into two parts, one
lower part from 12 to 20, and one upper part from 34 to 40.
I have tried to follow the basic ideas from the script provided here by
Jim Lemon:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/56487.html
My attempt looks like this:
###########################
# x-values
x <- 1:4
# small y-values with corresponding standard errors
meansarr <- c(14.9, 18.2, 14.5, 18.3)
searr <- c(0.47, 1.27, 1.22, 0.49)
# large values
meanslay <- c(36.4, 39.0, 35.3, 38.6)
selay <- c(0.51, 0.34, 0.57, 0.40)
library(plotrix)
# plot small values
plot(x, meansarr, ylim=c(12, 30), axes=F, type="b", xlab="",
ylab="Day")
arrows(x, meansarr-searr, x, meansarr+searr, code = 3, angle = 90,
length = 0.03)
box()
# x-axis
axis(1, tck=0.01, las=1, at=1:4,
labels=c("1998", "1999", "2002",
"2003"), mgp=c(3, 0.5, 0))
# y-axis
axis(2,at=c(12, 14, 16, 18, 20, 24, 26, 28,
30),labels=c("12","14","16","18","20",
"34","36","38","40"))
# break axis
axis.break(2, 22, style="zigzag")
# add large values to same plot
par(new=TRUE)
plot(x, meanslay, ylim=c(30, 40), type="b", xlab="",
ylab="Day", axes=F)
arrows(x, meanslay-selay, x, meanslay+selay, code = 3, angle = 90,
length = 0.03)
################################
As you can see, I have problems adding the larger y-values - they end up
in the wrong place in the graph. I suppose Jim's warning 'just be
careful that the ylim= and labels= arguments match up' is relevant here,
but I don't manage to fix it...
Can anyone help me to plot the large y-values on the right
placeaccording to the y-axis labeling?
I am using R 2.3.1 and WinXp.
Thanks a lot in advance!
Henrik
////
--
************************
Henrik P?rn
Department of Biology
NTNU
7491 Trondheim
Norway
+47 735 96282 (office)
+47 909 89 255 (mobile)
+47 735 96100 (fax)