Dear List, I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 E longitude). I would like to draw the richness in the north hemisphere and a regression line in the plot (x-axis: latitude, y-axis: richness in the north hemisphere). The above demand is done using plot. Then, south hemisphere richness and regression are required to be generated using the same y-axis above but an x-axis on the left side of the y-axis. (The higher latitude in the south hemisphere, the left it would move) Please kindly share how to design the south plot and regression line for richness. Also, please advise if any more info is in need. Elaine [[alternative HTML version deleted]]
On Aug 24, 2010, at 7:12 PM, elaine kuo wrote:> Dear List, > > I have a richness data distributing across 20 N to 20 S latitude. > (120 E-140 > E longitude). > > > I would like to draw the richness in the north hemisphere and a > regression > line in the plot > (x-axis: latitude, y-axis: richness in the north hemisphere). > The above demand is done using plot. > > Then, south hemisphere richness and regression are required to be > generated > using > the same y-axis above but an x-axis on the left side of the y-axis. > (The higher latitude in the south hemisphere, the left it would move) > > Please kindly share how to design the south plot and regression line > for > richness. > Also, please advise if any more info is in need.Reproducible code, .... now and forever shall be .... world without end, amen.> #------------------ > and provide commented, minimal, self-contained, reproducible code.#------------------ David Winsemius, MD West Hartford, CT
On Wed, 2010-08-25 at 07:12 +0800, elaine kuo wrote:> Dear List, > > I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 > E longitude). > > > I would like to draw the richness in the north hemisphere and a regression > line in the plot > (x-axis: latitude, y-axis: richness in the north hemisphere). > The above demand is done using plot. > > Then, south hemisphere richness and regression are required to be generated > using > the same y-axis above but an x-axis on the left side of the y-axis. > (The higher latitude in the south hemisphere, the left it would move)Elaine, It is not very clear what it is that you want here. Two plot panels on the same device like: layout(1:2) plot(1:100) plot(1:100) layout(1) The second panel for southern species richness, do you mean you want the plot to go like this: plot(1:100, xlim = c(100,1)) i.e. back to front to the normal axis limits? If so, you'll need to produce a regression model for southern richness just as you would for northern richness, but then predict from it at a sequence of latitude values that covers the range of your southern hemisphere observations, then plot these predictions versus the sequence of latitudes using lines(). For example, say you have: set.seed(123) rich <- data.frame(richness = rpois(100, lambda = 5), latitude = sample(seq(0, 90, length = 1000), 100)) plot(richness ~ latitude, data = rich, xlim = c(90,0)) ## ignoring that this is a count and might be more meaningfully ## modelled using a Poisson GLM mod <- lm(richness ~ latitude, data = rich) ## new prediction data, 100 equally spaced latitudes pdat <- data.frame(latitude = seq(0, 90, length = 100)) pdat <- within(pdat, richness <- predict(mod, newdata = pdat)) lines(richness ~ latitude, data = pdat, col = "red") If that doesn't help, we'll need more info. HTH G> Please kindly share how to design the south plot and regression line for > richness. > Also, please advise if any more info is in need. > > Elaine > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
On 08/25/2010 09:12 AM, elaine kuo wrote:> Dear List, > > I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 > E longitude). > > > I would like to draw the richness in the north hemisphere and a regression > line in the plot > (x-axis: latitude, y-axis: richness in the north hemisphere). > The above demand is done using plot. > > Then, south hemisphere richness and regression are required to be generated > using > the same y-axis above but an x-axis on the left side of the y-axis. > (The higher latitude in the south hemisphere, the left it would move) > > Please kindly share how to design the south plot and regression line for > richness. > Also, please advise if any more info is in need. >Hi Elaine, Changing the position of the axes is easily done by changing the "side" and "pos" arguments of the "axis" function. If you want to move the y-axis to the right (or as you state it, the x axis to the left): # y axis on the left plot(1:5,axes=FALSE) axis(1) axis(2) # add a y axis one third of the way to the right xylim<-par("usr") axis(2,pos=xylim[1]+diff(xylim[1:2])/3) # add another y axis two thirds of the way axis(4,pos=xylim[2]-diff(xylim[1:2])/3) # add one more on the right axis(4) You can move the x axis up and down using the same tricks. Jim
Dear Elaine I'm developing a code to make a 3 y-axes plot. It may can help you. Also your question leads to mine, posted yesterday: How does R calculate the interval between tick-marks. Below follows the code I'm developing. Data: ANO CKG NUP NDE 2005 26352158 1500 25014 2006 32514789 2100 35024 2007 27458126 1800 30254 2008 28568971 1500 43254 2009 32564789 3000 60320 Code: # I use comma as decimal symbol so I use dec="," dat.caupde <- read.delim("clipboard",dec=",",header=T) attach(dat.caupde) summary(dat.caupde) ANO CKG NUP NDE Min. :2005 Min. :26352158 Min. :1500 Min. :25014 1st Qu.:2006 1st Qu.:27458126 1st Qu.:1500 1st Qu.:30254 Median :2007 Median :28568971 Median :1800 Median :35024 Mean :2007 Mean :29491767 Mean :1980 Mean :38773 3rd Qu.:2008 3rd Qu.:32514789 3rd Qu.:2100 3rd Qu.:43254 Max. :2009 Max. :32564789 Max. :3000 Max. :60320 # here I indicate the limits of each axes and calculate their ranges y1min <- 26 y1max <- 33 y1range <- y1max-y1min y2min <- 1500 y2max <- 3000 y2range <- y2max-y2min y3min <- 25 y3max <- 61 y3range <- y3max-y3min # making the plot # y1range*((NUP-y2min)/y2range)+y1min calculates the proportion to between axes par(mar=c(6, 6, 2,12)) plot(CKG/1000000, ylim=c(y1min,y1max), ylab="landings (1000 t)", type="l",col="red",las=0, cex.axis=1.2,cex.lab=1.4,xaxt="n",xlab="") points( y1range*((NUP-y2min)/y2range)+y1min,type="l",col="blue") points( y1range*((NDE/1000-y3min)/y3range)+y1min,type="l",col="darkgreen") # the number 1 in axis(4,at=seq(y1min,y1max,1 ... is the interval between each tick-mark axis(1,at=1:5,labels=as.character(ANO),las=2,cex.axis=1.2) axis(4,at=seq(y1min,y1max,1),labels=as.integer(seq(y2min,y2max,y2range/y1range)),las=0,cex.axis=1.2) axis(4,at=seq(y1min,y1max,1), labels=as.integer(seq(y3min,y3max,y3range/y1range)),cex.axis=1.2, las=0,line=5) mtext("n? of fishing boats",4,3,cex=1.4) mtext("n? of fishing trips (x1000)",4,8, cex=1.4) legend(4,33,c("L","N? FB","N? FT"),bty="n",lty=c(1,1,1),col=c("red","blue","darkgreen"),cex=1.4) Now I want to replace the number "1" by the formula used to calculate the interval between tick-marks. Why, with the range 26-33, R choose unitary intervals for the y axis (26, 27, 28 ...)? All the best, Antonio Olinto Citando elaine kuo <elaine.kuo.tw at gmail.com>:> Dear List, > > I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 > E longitude). > > > I would like to draw the richness in the north hemisphere and a regression > line in the plot > (x-axis: latitude, y-axis: richness in the north hemisphere). > The above demand is done using plot. > > Then, south hemisphere richness and regression are required to be generated > using > the same y-axis above but an x-axis on the left side of the y-axis. > (The higher latitude in the south hemisphere, the left it would move) > > Please kindly share how to design the south plot and regression line for > richness. > Also, please advise if any more info is in need. > > Elaine > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >---------------------------------------------------------------- Webmail - iBCMG Internet http://www.ibcmg.com.br