简体   繁体   English

在绘制等高线图时出现错误(如果(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

For the below data 对于以下数据

       > 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

I have created an map using ggmap 我已经使用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).

drawn contour map 绘制轮廓图

    > 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).

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. 另外,我想在此轮廓图中绘制df $ Precipitation。

The lat, long values are same across the entire dataset. 整个数据集中的lat, long值相同。 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. 因此,在两者的方差latlong方向为零,因此无法计算为内核密度估计(KDE)的带宽。

Hence, you are getting the error bandwidths must be strictly positive . 因此,您得到的错误bandwidths must be strictly positive

For calculating 2-D KDEs, the variance in both x and y direction need to positive. 为了计算2-D KDE,x和y方向的方差都必须为正。 You are getting the error twice as in your case variance in both directions are 0. 由于两次方差均为0,因此您会收到两次错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM