如何解决数据密度图的错误消息 "Discrete value supplied to continuous scale";差异功能?
How to resolve error message "Discrete value supplied to continuous scale" for data density plot; Diff function?
我在绘制我所在城市的犯罪密度图时遇到了一些问题。我正在通过 stat_density2d()
函数使用二维核密度估计。无论我如何更改 and/or rear运行ge,我都会不断收到错误消息
Discrete value supplied to continuous scale
I 运行 str
函数检查结构; Lon(gitude) 被读作一个字符。
OakTownMap +
stat_density2d(aes(x = lon, y = lat, fill = ..level.. ,alpha=..level..), bins = 10, geom ="polygon", data = Non_Violent_Crime) +
scale_fill_gradient(low = "black", high = "red")+
ggtitle("Map of Non-Violent Crime Density in Oakland ")
我真的迷路了,有点沮丧,因为我确信这需要对 lon 和 lat 参数的放置或函数的更改进行非常简单的调整 (?)。我应该将 lon 从 char 更改为 num 吗?
从屏幕截图看来,您需要将 lon 强制转换为数值向量。在将其添加到 ggplot 之前尝试 Non_Violent_Crimes$lon <- as.numeric(Non_Violent_Crimes$lon)
。或者,当您添加几何图形时,将 "x=lon" 更改为 "x=as.numeric(lon)"。这直接解决了您收到的错误。
我在绘制我所在城市的犯罪密度图时遇到了一些问题。我正在通过 stat_density2d()
函数使用二维核密度估计。无论我如何更改 and/or rear运行ge,我都会不断收到错误消息
Discrete value supplied to continuous scale
I 运行 str
函数检查结构; Lon(gitude) 被读作一个字符。
OakTownMap +
stat_density2d(aes(x = lon, y = lat, fill = ..level.. ,alpha=..level..), bins = 10, geom ="polygon", data = Non_Violent_Crime) +
scale_fill_gradient(low = "black", high = "red")+
ggtitle("Map of Non-Violent Crime Density in Oakland ")
我真的迷路了,有点沮丧,因为我确信这需要对 lon 和 lat 参数的放置或函数的更改进行非常简单的调整 (?)。我应该将 lon 从 char 更改为 num 吗?
从屏幕截图看来,您需要将 lon 强制转换为数值向量。在将其添加到 ggplot 之前尝试 Non_Violent_Crimes$lon <- as.numeric(Non_Violent_Crimes$lon)
。或者,当您添加几何图形时,将 "x=lon" 更改为 "x=as.numeric(lon)"。这直接解决了您收到的错误。