Reputation: 23
I'm trying to make a hexagonal heatmap of some data using geom_hex
, but the plot displayed is empty, like this :
(empty plot)
I'm pretty sure the error doesn't come from my code, since when using similar code to plot a square heatmap, the plot is displayed correctly. Does anyone have a clue where that comes from, or any way to understand what ggplot2 is doing in this situation ?
Here is my code, this is the source of the data.
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
Upvotes: 2
Views: 862
Reputation: 60
I got a similar display error when trying to replicate. Try installing and calling the 'hexbin' package, should do the trick.
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
Upvotes: 3