[R] Contour plot with messy field data.

chuck.01 CharlieTheBrown77 at gmail.com
Fri Feb 3 06:59:13 CET 2012


This is ugly, but I think it works.:

z.2 <- data.frame(data.interp[[3]])
diff_y <- unique(round(diff(data.interp[[2]]), 4))
diff_x <- unique(round(diff(data.interp[[1]]), 4))
total_area <- length(which(z.2!="NA"))*diff_y*diff_x

# percent of total area less than  -.5 (as I wanted)
Per_neg_0.5 <- (length(which(z.2<=-.5))*diff_y*diff_x)/total_area

If you see a problem, please let me know. 




chuck.01 wrote
> 
> Ok, 
> I've since found this:
> 
> # called previously posted dataset "dat"
> 
> attach(dat)
> library(akima)
> data.interp <- interp(x,y,z) 
> contour(data.interp) 
> 
> 
> any idea how to calculate area within specified contour lines?
> 
> Thanks
> 
> 
> 
> 
> chuck.01 wrote
>> 
>> Hello, 
>> I have some data that will be in the form:
>> 
>> structure(list(station = structure(c(3L, 20L, 2L, 4L, 19L, 11L, 
>> 1L, 5L, 10L, 12L, 17L, 18L, 6L, 9L, 13L, 16L, 7L, 8L, 15L, 14L
>> ), .Label = c("1", "10", "11", "12", "13", "14", "15", "16", 
>> "17", "18", "19", "2", "3", "4", "5", "6", "7", "8", "9", "scope"
>> ), class = "factor"), distance = c(1.2, 0, 2, 0.8, 3, 1.7, 1, 
>> 1.4, 2.8, 2.2, 4.5, 4.2, 2.8, 3.6, 3.4, 4.8, 3.8, 4.2, 4.8, 4.4
>> ), degrees = c(-59, 0, 90, 89.9, 82.4, 69.4, 10.8, 45, 69, 26.6, 
>> 63.4, 61.6, 45, 56.3, 28.1, 51.7, 38.7, 45, 38.3, 25.4), z = c(0L, 
>> 0L, 0L, -1L, 0L, -1L, 0L, -1L, -1L, 0L, 0L, 0L, -1L, -1L, 0L, 
>> 0L, -1L, -1L, 0L, 0L), x = c(-0.6, 0, 0, 0, 0.4, 0.6, 1, 1, 1, 
>> 2, 2, 2, 2, 2, 3, 3, 3, 3, 3.8, 4), y = c(1, 0, 2, 0.8, 3, 1.6, 
>> 0.19, 1, 2.6, 1, 4, 3.7, 2, 3, 1.6, 3.8, 2.4, 3, 3, 1.9)), .Names =
>> c("station", 
>> "distance", "degrees", "z", "x", "y"), row.names = c(12L, 1L, 
>> 11L, 13L, 10L, 20L, 2L, 14L, 19L, 3L, 8L, 9L, 15L, 18L, 4L, 7L, 
>> 16L, 17L, 6L, 5L), class = "data.frame")
>> 
>> 
>> I would like to create a contour plot and eventually be able to calculate
>> the % area within each contour.  
>> This only has 2 contour lines of height z=0, and z=-1; I would like to
>> have as many and these z values likely won't fall nicely into a contour
>> with others.  Also, linear interpolation adding at least one point
>> between observed points would be great.   
>> 
>> This may give you an idea of the spatial arrangement of observations. 
>>  http://r.789695.n4.nabble.com/file/n4353603/Slide1.png 
>> 
>> Does anyone have any suggestions on how to begin doing this?
>> 
> 


--
View this message in context: http://r.789695.n4.nabble.com/Contour-plot-with-messy-field-data-tp4353603p4353754.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list