I would like to make this type of figure below in R, which is a combination of marginal histograms and a geom_hex object I think. This is originally a matplotlib seaborn graph.
I can't get it to talk to RColorbrewer. Any thoughts why?

So far I've got:
require(ggplot2)
require(RColorBrewer)
require(ggExtra)
bl<-data.frame(beta=rnorm(100),lambda=rnorm(100))
p<-ggplot(bl,aes(x=beta,y=lambda))+
stat_bin_hex()+
#scale_fill_gradient(palette = "Greens") Neither of these work
#scale_fill_continuous(palette = "Greens")+
scale_fill_brewer()+
theme_classic()
ggExtra::ggMarginal(p, type = "histogram")
Original code:
x, y = np.random.multivariate_normal(mean, cov, 1000).T
with sns.axes_style("white"):
https://seaborn.pydata.org/tutorial/distributions.html
sns.jointplot(x=x, y=y, kind="hex", color="greens");
You can use scale_fill_gradientn and pass in the palette using brewer.pal. Then you just need to pass in the right fill and color to ggMarginal
library(ggplot2)
library(RColorBrewer)
library(ggExtra)
bl <- data.frame(beta=rnorm(10000),lambda=rnorm(10000))
p <- ggplot(bl, aes(x=beta, y = lambda))+
stat_bin_hex() +
scale_fill_gradientn(colors = brewer.pal(3,"Greens")) +
theme_classic() +
theme(legend.position = "bottom")
ggMarginal(p, type = "histogram", fill = brewer.pal(3,"Greens")[1], color = "white")

Created on 2018-11-20 by the reprex package (v0.2.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With