HCA*_*CAI 3 r matplotlib ggplot2 seaborn
我想在 R 中制作下面这种类型的图,我认为它是边缘直方图和 geom_hex 对象的组合。这最初是一个 matplotlib seaborn 图。
我无法让它与 RColorbrewer 交谈。任何想法为什么?
到目前为止,我有:
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")
Run Code Online (Sandbox Code Playgroud)
原始代码:
x, y = np.random.multivariate_normal(mean, cov, 1000).T
with sns.axes_style("white"):
Run Code Online (Sandbox Code Playgroud)
https://seaborn.pydata.org/tutorial/distributions.html
sns.jointplot(x=x, y=y, kind="hex", color="greens");
Run Code Online (Sandbox Code Playgroud)
您可以使用scale_fill_gradientn
,并使用通过调色板brewer.pal
。然后你只需要将正确的填充和颜色传递给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")
Run Code Online (Sandbox Code Playgroud)
由reprex 包(v0.2.1)于 2018 年 11 月 20 日创建