我想在我的boxplot中的"mean"之间添加一行.
我的代码:
library(ggplot2)
library(ggthemes)
Gp=factor(c(rep("G1",80),rep("G2",80)))
Fc=factor(c(rep(c(rep("FC1",40),rep("FC2",40)),2)))
Z <-factor(c(rep(c(rep("50",20),rep("100",20)),4)))
Y <- c(0.19 , 0.22 , 0.23 , 0.17 , 0.36 , 0.33 , 0.30 , 0.39 , 0.35 , 0.27 , 0.20 , 0.22 , 0.24 , 0.16 , 0.36 , 0.30 , 0.31 , 0.39 , 0.33 , 0.25 , 0.23 , 0.13 , 0.16 , 0.18 , 0.20 , 0.16 , 0.15 , 0.09 , 0.18 , 0.21 , 0.20 , 0.14 , 0.17 , 0.18 , 0.22 , …Run Code Online (Sandbox Code Playgroud) 看起来条带总是在ggplot2创建的图上方.他们可以移到情节之下吗?
例如:
library(ggplot2)
qplot(hwy, cty, data = mpg) + facet_grid( . ~ manufacturer)
Run Code Online (Sandbox Code Playgroud)
在顶部显示汽车信息.它们可以显示在底部吗?
我想将我的一个分组箱线图(如下)替换为前后类型,但保持分组。这个是使用ggboxplot()from 制作的ggpubr。我知道也有,ggpaired()但我无法像这样分组。
由于这个问题,我能够创建像这样的分组前后图。我现在想将轴从 4 个标记更改为 2 个(只是“是”和“否”,因为“之前”和“之后”仍在图例中。

这是我的带有虚拟数据的代码:
library(tidyverse)
set.seed(123)
data.frame(ID = rep(LETTERS[1:10], 2),
consent = rep(sample(c("Yes", "No"), 10, replace = T), 2),
height = sample(rnorm(20, 170, sd = 10)),
ind = rep(c("before", "after"), each = 2)
) %>%
ggplot(aes(x = interaction(ind, consent), y = height, color = ind))+
geom_point()+
geom_line(aes(group = interaction(ID, consent)), color = "black")+
scale_x_discrete("response")
Run Code Online (Sandbox Code Playgroud)
甚至可以减少轴上的类别数量吗?或者我可以使用ggpaired(),但不使用构面创建分组图吗?
我正在尝试使用类似于此问题中描述的连接线创建一个简单的箱线图:使用线和多个因子连接ggplot箱图.但是,该示例中的交互术语会产生错误:
geom_path:每组只包含一个观察.你需要调整群体美感吗?
我想使用索引变量连接每个点.这是代码:
group <- c("A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B","B")
session <- c("one","two","one","two","one","two","one","two","one","two","one","two","one","two","one","two","one","two","one","two")
value <- c(1.02375,1.01425,1.00505,0.98105,1.09345,1.09495,0.98255,0.90240,0.99185,0.99855,0.88135,0.72685,0.94275,0.84775,1.01010,0.96825,0.85215,0.84175,0.89145,0.86985)
index <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10)
df <- data.frame(group,session,value,index)
# Graph plots
p <- ggplot(df, aes(x=group, y=value, fill=session))
p <- p + geom_boxplot(color="grey40", outlier.alpha=0.0) #alpha=0.6
p <- p + stat_summary(fun.y=mean,geom="point",pch="-",color="white",size=8, position = position_dodge(width=0.75)) # size=2 color="black"
p <- p + geom_point(size=2, alpha=0.6, aes(group=session), data=df, position = position_dodge(width=0.75))
p <- p + geom_line(aes(group = index), alpha = 0.6, colour = "black", position = position_dodge(width=0.75), data=df) #
p <- p + …Run Code Online (Sandbox Code Playgroud)