Reputation: 845
The code to generate sample dataset:
templ = data.frame(count = c(200,225,610,233,250,210,290,255,279,250),
temperature = c(12.2,11.6,12,8.5,4,8.2,9.2,10.6,10.8,10.9),
relative_humidity_percent = c(74,78,72,65,77,84,83,74,73,75))
I used stats_summary_2d to generate the following graph:
ggplot(templ, aes(temperature, relative_humidity_percent, z = count)) +
stat_summary_2d(bins = 5) +
viridis::scale_fill_viridis() +
theme_classic()+
theme(panel.background = element_rect(fill = "black"))
But I want the graph to be more smooth, something like:
Is it possible to generate this type of graph by using stats_summary_2d
?
I googled and found very few result about this...
Upvotes: 0
Views: 68
Reputation: 17309
You could tidyr::uncount()
your data, then use geom_density_2d_filled()
.
library(ggplot2)
library(tidyr)
templ %>%
uncount(count) %>%
ggplot(aes(temperature, relative_humidity_percent)) +
geom_density_2d_filled(show.legend = FALSE) +
theme_classic() +
coord_cartesian(expand = FALSE)
Upvotes: 2