gpt4 book ai didi

r - geom_blank 丢弃 NA

转载 作者:行者123 更新时间:2023-12-04 01:03:43 31 4
gpt4 key购买 nike

使用 geom_blank我想添加一些新的因子水平,但我似乎无法这样做并保留 NA水平

library('ggplot2')
pl <- ggplot(data.frame(x = factor(c(1:2, NA)), y = 1), aes(x, y)) + geom_point()
pl

enter image description here
pl + geom_blank(data = data.frame(x = addNA(factor(c(0:3, NA))), y = 1))

enter image description here

我想使用 geom_blank 将 x 设为 0,1,2,3,NA

最佳答案

正如我在评论中所希望的那样,如果绘图已经完成,解决方法可能是重新排序图层,这通常适用于 ggplots。

library('ggplot2')
pl <- ggplot(data.frame(x = factor(c(1:2, NA)), y = 1), aes(x, y)) +
geom_point() +
geom_blank(data = data.frame(x = addNA(factor(c(0:3, NA))), y = 1))


## not what I want
pl


## this is what I want
pl$layers <- rev(pl$layers)
pl

enter image description here

关于r - geom_blank 丢弃 NA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648451/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com