问题描述
stat_bin2d(bins = 19,aes(fill = after_stat(density))) +
出现以下错误:Could not find function "stat_bindot"
我在谷歌上搜索了这个问题,读到可能是该功能已在最新版本中删除。
我还能如何将点绘制为圆而不是矩形?
示例代码:
数据集是要绘制的 X 和 Y 坐标(在单独的列中)的列表。
library(ggplot2)
ggplot(data = my.project_data,aes(x = CoordX,y = CoordY)) +
sstat_bin2d(bins = 19,aes(fill = after_stat(density))) +
scale_fill_gradient(name = "Percent",low = "#ddddDD",high = "#000000",labels = scales::percent)
解决方法
如果您想将类似平铺的显示更改为圆形,您可以将 geom
参数更改为 stat_bin2d()
。下面是标准数据集的示例:
library(ggplot2)
ggplot(data = faithful,aes(x = eruptions,y = waiting)) +
stat_bin2d(bins = 19,aes(colour = after_stat(density),fill = NULL),geom = "point",size = 5) +
scale_colour_gradient(name = "Percent",low = "#DDDDDD",high = "#000000",labels = scales::percent)
由 reprex package (v1.0.0) 于 2021 年 4 月 23 日创建