相关疑难解决方法(0)

在ggplot2对象中的现有图层下插入图层

鉴于现有的剧情对象是有可能添加层UNDERNEATH现有图层?

例如,在下面的图表中,是有可能添加geom_boxplot()P使得出现箱线图下方 geom_point()

## Starting from: 
library(ggplot2)
P <- ggplot(data=dat, aes(x=id, y=val)) + geom_point()

## This adds boxplot, but obscures some of the points
P + geom_boxplot()
Run Code Online (Sandbox Code Playgroud)

预期产出:

# Which is essentially
ggplot(data=dat, aes(x=id, y=val)) + geom_boxplot() + geom_point()
## However, this involves re-coding all of P (after the point insertion of the new layer).
##   which is what I am hoping to avoid. 
Run Code Online (Sandbox Code Playgroud)

示例输出


额外问题: 如果现有图中有多个图层,是否可以指示插入新图层的具体位置(相对于现有图层)?


样本数据

set.seed(1)
N <- 100
id …
Run Code Online (Sandbox Code Playgroud)

r layer ggplot2

23
推荐指数
2
解决办法
3403
查看次数

标签 统计

ggplot2 ×1

layer ×1

r ×1