ggplot2 - Trouble displaying contours in R and ggplot with basic dataset -


i trying plot nmds co-ordinates x , y, , use diversity measure (shannon)to plot contour keep getting following error , can't see why...

error in if (empty(new)) return(data.frame()) :    missing value true/false needed 

my code is:

all_merge <-read.table("test.txt", header=true)   p <- ggplot(all_merge, aes(nmds1, nmds2, z = shannon))  p + geom_contour() 

and dataset is:

nmds1   nmds2   shannon -0.287555952    -0.129887595    9.516558582 -0.314104852    -0.048655648    8.985087924 -0.214910534    -0.127167065    8.928241917 -0.341295065    -0.296282805    8.315476782 -0.470025718    0.083835083 8.494348157 -0.429386114    0.044064347 8.669813919 -0.427608469    0.124631936 8.15886319 -0.584412991    0.257278736 8.469688185 -0.436526047    -0.070633108    8.496878956 -0.584707076    0.120411579 8.319057817 0.183493022 0.445239412 5.611249955 0.172968855 0.583787121 5.728358304 -0.404838098    -0.0271276  8.679667562 -0.458718755    -0.05638174 8.714026645 0.458621093 -0.186746574    8.094002558 1.148457698 0.044192391 6.058046032 0.346825668 0.258443444 6.682765975 0.753149083 -0.393018506    7.622032803 1.331546069 -0.515095457    5.784195943 0.236285309 0.2553056   7.210095451 0.346995457 -0.816928807    7.198583726 0.137626646 0.129803823 7.663931393 0.340733689 -0.461201268    5.845269914 -0.675116235    -0.037255181    8.371975231 -0.656523041    -0.025798291    8.438133054 -0.578757804    -0.073169316    8.411583639 -0.602672875    0.015207904 8.137468395 0.413598703 0.320133927 5.91489704 0.891714173 1.032329752 3.612230592 0.378252162 0.054121091 7.903450498 0.401158365 0.009307957 8.164654685 -0.074266368    -0.512745143    8.956733268 

geom_contour (stat_contour) not work on irregular grids (see here). 1 way create regular grid use interpolation function interp in package akima.

library(akima) library(reshape2)  # interpolate data regular grid d1 <- with(all_merge, interp(x = nmds1, y = nmds2, z = shannon))  # melt z matrix in d1 long format ggplot d2 <- melt(d1$z, na.rm = true) names(d2) <- c("x", "y", "shannon")  # add nmds1 , nmds2 d1 using corresponding index in d2 d2$nmds1 <- d1$x[d2$x] d2$nmds2 <- d1$y[d2$y]  # plot ggplot(data = d2, aes(x = nmds1, y = nmds2, fill = shannon, z = shannon)) +   geom_tile() +   stat_contour() 

enter image description here


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -