在将等高线图绘制为(if if if(any(h< = 0))stop(“带宽必须严格为正"时出错):在R中 [英] Getting Error while plotting contour map as (Error in if (any(h <= 0)) stop("bandwidths must be strictly positive") : in R

查看:281
本文介绍了在将等高线图绘制为(if if if(any(h< = 0))stop(“带宽必须严格为正"时出错):在R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下数据

       > head(df)

      Date Longitude Latitude Elevation Max.Temperature Min.Temperature Precipitation     Wind Relative.Humidity    Solar  RO
     1 2014-07-01   77.1875  7.96184     -9999          27.725          26.673  16.115560560 8.395378         0.8132272 23.08192 Yes
     2 2014-07-02   77.1875  7.96184     -9999          27.931          26.897   0.700378560 8.062267         0.8074675 21.48473 Yes
     3 2014-07-03   77.1875  7.96184     -9999          28.179          26.686   0.000000000 9.465022         0.8107901 24.14900  No
     4 2014-07-04   77.1875  7.96184     -9999          27.657          26.545   0.003433226 9.397203         0.8195020 23.42036 Yes
     5 2014-07-05   77.1875  7.96184     -9999          27.157          26.490   1.541518560 8.903047         0.8385059 23.90545 Yes
     6 2014-07-06   77.1875  7.96184     -9999          27.308          26.481   0.000000000 8.617348         0.8205267 23.96318  No

我已经使用ggmap创建了地图

I have created an map using ggmap

     > Precip_map<-get_map(location="india",maptype="satellite",zoom=12)

        Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=india&zoom=12&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false

     > ggmap(Precip_map, extent = "device") + geom_point(aes(x = Longitude, y = Latitude), colour = "red", 
     +     alpha = 0.1, size = 2, data = df)

     Warning message:
    In loop_apply(n, do.ply) :
    Removed 1106 rows containing missing values (geom_point).

绘制等高线图

    > ggmap(Precip_map, extent = "device") + geom_density2d(data = df, 
    +     aes(x = Longitude, y = Latitude), size = 0.3) + stat_density2d(data = df, 
    +     aes(x = Longitude, y = Latitude, fill = ..level.., alpha = ..level..), size = 0.01, 
    +     bins = 16, geom = "polygon") + scale_fill_gradient(low = "green", high = "red", 
    +     guide = FALSE) + scale_alpha(range = c(0, 0.3), guide = FALSE)

     Error in if (any(h <= 0)) stop("bandwidths must be strictly positive") : 
     missing value where TRUE/FALSE needed
     Error in if (any(h <= 0)) stop("bandwidths must be strictly positive") : 
     missing value where TRUE/FALSE needed
     In addition: Warning message:
     In loop_apply(n, do.ply) :
     Removed 1106 rows containing non-finite values (stat_density2d).
     Warning message:
     In loop_apply(n, do.ply) :
     Removed 1106 rows containing non-finite values (stat_density2d).

我不知道我到底在哪里...我是这个映射的新手..请帮助我.另外,我想在此轮廓图中绘制df $ Precipitation.

I dont know exactly where i am lacking.. i am new to this mapping.. please assist me. Also, I want to plot df$Precipitation in this contour map.

推荐答案

在整个数据集中,lat, long值相同.因此,latlong方向的方差均为零,因此无法计算内核密度估计(KDE)的带宽.

The lat, long values are same across the entire dataset. Hence, the variance in both the lat and long direction is zero, so a bandwidth for the kernel density estimate (KDE) can't be calculated.

因此,您收到错误bandwidths must be strictly positive.

要计算二维KDE,x和y方向的方差都必须为正.您将得到两次错误,因为在这种情况下,两个方向的方差均为0.

For calculating 2-D KDEs, the variance in both x and y direction need to positive. You are getting the error twice as in your case variance in both directions are 0.

这篇关于在将等高线图绘制为(if if if(any(h&lt; = 0))stop(“带宽必须严格为正"时出错):在R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆