仅为某些箱线图绘制抖动点
Plot jitter points for certain boxplots only
我有五个包含矩阵形式数据的文件,我正在使用 geom_boxplot 绘制它。每个箱线图对应一个文件。
我想要实现的只是某些文件,这里说 div1,div3,div5 我想绘制箱线图,其中数据点覆盖在箱线图上。我可以使用 geom_jitter 添加数据点,但我必须将那些带有数据点的图与唯一的箱线图分开。
因为我想保留绘制文件的顺序。.i.e div0,div1..等。我不能只为某些箱线图绘制数据点。
如何只为某些箱线图而不是所有箱线图添加叠加数据点?
files <- c(div0,div1,div2,div3,div4,div5)
p1 <- ggplot(moltenNew,aes(x=L1,y=value,colour=L1))+ ylim(0.3,0.8) +
geom_boxplot() + facet_wrap(~variable,nrow=1) + scale_x_discrete(limits = basename(files) ,labels = basename(files))
![enter image description here][1]
您可以使用 subset
:
set.seed(1)
moltenNew <- rbind(
data.frame(value = rnorm(20, 50, 20), L1 = gl(2, 10), variable = 1),
data.frame(value = rnorm(20, 100, 100), L1 = gl(2, 10), variable = 2),
data.frame(value = rnorm(20, 75, 10), L1 = gl(2, 10), variable = 3)
)
moltenNew
library(ggplot2)
ggplot(moltenNew,aes(x=L1,y=value,colour=L1)) +
geom_boxplot() +
facet_wrap(~variable,nrow=1, scale = "free_y") +
geom_point(subset = .(variable == 2), position = position_jitter(width = .2))
我有五个包含矩阵形式数据的文件,我正在使用 geom_boxplot 绘制它。每个箱线图对应一个文件。
我想要实现的只是某些文件,这里说 div1,div3,div5 我想绘制箱线图,其中数据点覆盖在箱线图上。我可以使用 geom_jitter 添加数据点,但我必须将那些带有数据点的图与唯一的箱线图分开。
因为我想保留绘制文件的顺序。.i.e div0,div1..等。我不能只为某些箱线图绘制数据点。
如何只为某些箱线图而不是所有箱线图添加叠加数据点?
files <- c(div0,div1,div2,div3,div4,div5)
p1 <- ggplot(moltenNew,aes(x=L1,y=value,colour=L1))+ ylim(0.3,0.8) +
geom_boxplot() + facet_wrap(~variable,nrow=1) + scale_x_discrete(limits = basename(files) ,labels = basename(files))
![enter image description here][1]
您可以使用 subset
:
set.seed(1)
moltenNew <- rbind(
data.frame(value = rnorm(20, 50, 20), L1 = gl(2, 10), variable = 1),
data.frame(value = rnorm(20, 100, 100), L1 = gl(2, 10), variable = 2),
data.frame(value = rnorm(20, 75, 10), L1 = gl(2, 10), variable = 3)
)
moltenNew
library(ggplot2)
ggplot(moltenNew,aes(x=L1,y=value,colour=L1)) +
geom_boxplot() +
facet_wrap(~variable,nrow=1, scale = "free_y") +
geom_point(subset = .(variable == 2), position = position_jitter(width = .2))