[R] Help reproducing a contour plot

David Winsemius dwinsemius at comcast.net
Wed Sep 19 23:58:25 CEST 2012


On Sep 19, 2012, at 8:55 AM, Tinus Sonnekus wrote:

> Hi All,
> 
> I am trying to reproduce this using R instead.
> 
> [image: Full-size image (38 K)]
> 
> 
> I tried using the following code
> 
> *SChla <- read.csv("SM_Chla_data.csv")*
> 
> *Atlantis <- SChla[16:66,]*
> *head(Atlantis)*
> *
> *
>   Seamount Station   Depth   Pico   Nano  Micro Total_Ch    dbar  Latitude
> Longitud
> 16 Atlantis    1217 Surface 0.0639 0.1560 0.0398   0.2597   2.082 -32.71450
> 57.29733
> 17 Atlantis    1217 Shallow 0.0305 0.1250 0.0740   0.2295  24.524 -32.71450
> 57.29733
> 18 Atlantis    1217    Deep 0.1660 0.3560 0.0734   0.5954  49.573 -32.71450
> 57.29733
> 19 Atlantis    1217    Fmax 0.1740 0.5200 0.1830   0.8770  79.595 -32.71450
> 57.29733
> 20 Atlantis    1217   Below 0.0235 0.0486 0.0242   0.0963 199.067 -32.71450
> 57.29733
> 21 Atlantis    1225 Surface 0.0764 0.1490 0.0333   0.2587   0.409 -32.71133
> 57.27150
> 
> *# Obtaining longitude and depth data*
> *Long <- SMfrac[,6]*
> *dbar <- -SMfrac[,5] #reverse depth*
> *
> *
> *#converting data to percentage of total chl a*
> *
> *
> *picoFrac <- Atlantis$Pico/Atlantis$Total_Ch*100*
> *nanoFrac <- Atlantis$Nano/Atlantis$Total_Ch*100*
> *microFrac <- Atlantis$Micro/Atlantis$Total_Ch*100*
> *
> *
> *
> *
> *library(akima)*
> *
> *
> *par(mfrow = c(3,1)) *
> *
> *
> *contour(interp(Long, dbar, picoFrac),nlevels = 6,*
> * xlab ="Longitude", main= "Pico", *
> *       ylab ="Depth", ylim = c(-200,0), method = "simple",*
> *       col = "light green")*
> *
> *
> *contour(interp(Long, dbar, nanoFrac), nlevels = 6,*
> * xlab ="Longitude", main= "Nano",*
> *       ylab ="Depth",ylim = c(-200,0), method = "simple",*
> *       col = "green")*
> *
> *
> *contour(interp(Long, dbar, microFrac),nlevels = 6,*
> * xlab ="Longitude", main= "Micro",*
> *       ylab ="Depth",ylim = c(-200,0),     *
> *       lylab ="Depth", method = "simple",*
> *       col = "dark green")*
> 
> I can get the contours plotted. Not sure if this is 100 % correct but it
> looks as expected. Can you guys please help me to add/display my data
> points. I would also like to fill the contours in grayscale/colour (e.g.
> levels 0, 20, 40, 60, 80. 100 %) and add a legend to the graph. As of yet I
> haven't tried to figure out how to add the stations as a secondary axis to
> the plot.
> 

Why wouldn't you just use the points() function after each contour?

-- 
David.



David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list