R geom_hex(ggplot2)显示一个空绘图

R geom_hex(ggplot2)显示一个空绘图,r,ggplot2,plot,R,Ggplot2,Plot,我试图使用geom_hex制作一些数据的六边形热图,但显示的图是空的,如下所示: 我很确定错误不是来自我的代码,因为当使用类似的代码绘制方形热图时,该图显示正确。有没有人知道这是从哪里来的,或者有没有人知道ggplot2在这种情况下做了什么 这是我的代码,这是最新的数据 cab <- read.csv("yellow_tripdata_2018-06.csv") cab <- cab[sample(nrow(cab), 10000), ] library(ggplot2) taxi

我试图使用
geom_hex
制作一些数据的六边形热图,但显示的图是空的,如下所示:

我很确定错误不是来自我的代码,因为当使用类似的代码绘制方形热图时,该图显示正确。有没有人知道这是从哪里来的,或者有没有人知道ggplot2在这种情况下做了什么

这是我的代码,这是最新的数据

cab <- read.csv("yellow_tripdata_2018-06.csv")
cab <- cab[sample(nrow(cab), 10000), ]
library(ggplot2)
taxic <- ggplot(cab, aes(x=tip_amount, y=fare_amount)) + 
         geom_hex() + 
         xlab("tip amount") + ylab("fare amount") +
         xlim(0,15) + ylim(0,75) +
         ggtitle("hexagonal heatmap of tip amount vs. fare amount")
taxic

cab我在尝试复制时遇到了类似的显示错误。尝试安装并调用“hexbin”包,应该可以做到这一点

install.packages('hexbin')
library(hexbin)
library(ggplot2)

cab <- read.csv("yellow_tripdata_2018-06.csv")
cab <- cab[sample(nrow(cab), 10000), ]
taxic <- ggplot(cab, aes(x=tip_amount, y=fare_amount)) + 
         geom_hex() + 
         xlab("tip amount") + ylab("fare amount") +
         xlim(0,15) + ylim(0,75) +
         ggtitle("hexagonal heatmap of tip amount vs. fare 
         amount")
taxic
install.packages('hexbin'))
图书馆(合宾)
图书馆(GG2)
成功了!!非常感谢(仅供参考,我安装了该软件包,但不需要在代码中调用库(hexbin))