繁体   English   中英

ggplot图与facet_wrap和fill混淆

[英]ggplot plot confusion with facet_wrap and fill

我有以下数据框:

x| y | z | d
1| 0 | A | 0.1
2| 1 | B | 0.01
3| 0 | C | 0.01

哪里:

x是随机数。
y为0或1。
z是finit模型。
d在0到1之间。

我想使用z创建facet_wrap ,并使用以下代码通过y填充它:

ggplot(df, aes(x = x, fill=y)) +
 geom_density(alpha = .5) +
 xlim(c(0,.10)) +
 theme_bw() +
 facet_wrap(~z)

如何绘制呢?

因为您的填充变量应该是一个因子或组。 这是您的问题的复制品,我为数据框使用了不同的值:

x <- rnorm(99)
y <- rbinom(99,1,.5)
Z <- rep(c("A", "B","C"), 33)
d <- runif(99)

ggplot(dd) +
  geom_density(alpha = .5, aes(x = x, fill = as.factor(y))) +
  theme_bw() +
  facet_wrap(~z)

我取出xlim是因为值并不都在该范围内,这是曲线图:

情节

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM