问题描述
我正在尝试使用因子x轴和errorbar plot
的每个级别内的躲避组向x-axis
添加重要性注释。它与this
我的基本错误栏图是:
library(ggplot2)
library(dplyr)
pres_prob_pd = structure(list(x = structure(c(1,1,2,3,3),labels = c(`1` = 1,`2` = 2,`3` = 3)),predicted = c(0.571584427222816,0.712630712634987,0.156061969566517,0.0162388386564817,0.0371877245103279,0.0165022541901018,0.131528946944238,0.35927812866896,0.0708662221985375),std.error = c(0.355802875027348,0.471253661425626,0.457109887762665,0.352871728451576,0.442646879181155,0.425913568532558,0.376552208691762,0.48178172708116,0.451758041335245
),conf.low = c(0.399141779923204,0.496138837620712,0.0701919316506831,0.00819832576725402,0.0159620304815404,0.00722904089045731,0.0675129352870401,0.17905347369819,0.030504893442457),conf.high = c(0.728233665534388,0.861980236164486,0.311759350126477,0.031911364587827,0.0842227723261319,0.0372248587668487,0.240584344249407,0.590437963881823,0.156035177669385
),group = structure(c(1L,2L,3L,1L,3L),.Label = c("certain","neutral","uncertain"),class = "factor"),group_col = structure(c(1L,language = structure(c(2L,.Label = c("english","dutch","german"
),top = c(0.861980236164486,0.590437963881823)),row.names = c(NA,-9L),groups = structure(list(language = structure(1:3,"german"),.rows = structure(list(
4:6,1:3,7:9),ptype = integer(0),class = c("vctrs_list_of","vctrs_vctr","list"))),class = c("tbl_df","tbl","data.frame"),.drop = TRUE),class = c("grouped_df","tbl_df","data.frame"))
#dodge
pd = position_dodge(.75)
#plot
p = ggplot(pres_prob_pd,aes(x=language,y=predicted,color=group,shape=group)) +
geom_point(position=pd,size=2) +
geom_errorbar(aes(ymax=conf.high,ymin=conf.low),width=.125,position=pd)
p
我想要做的是对图进行注释,以便对group
的每个级别内language
之间的对比度进行注释以显示重要性。我绘制了代表相关对比和(玩具)信号的点。注释如下:
#bump function
f = function(x){
v = c()
bump=0.025
constant = 0
for(i in x){
v = c(v,i+constant+bump)
bump = bump + 0.075
}
v
}
#create contrasts
combs = data.frame(gtools::combinations(3,v=c("certain",set=F,repeats.allowed=F)) %>%
mutate(contrast=c("cont_1","cont_2","cont_3"))
combs = rbind(combs %>% mutate(language = 'english'),combs %>% mutate(language='dutch'),combs %>% mutate(language = "german")) %>%
left_join(select(pres_prob_pd,language:top)%>%distinct(),by='language') %>%
group_by(language)
#long transform and calc y_pos
combs_long = mutate(combs,y_pos=f(top)) %>% gather(long,probability,X1:X2,factor_key=TRUE) %>% mutate(language=factor(language,levels=c("english","german"))) %>%
arrange(language,contrast)
#back to wide
combs_wide =combs_long %>% spread(long,probability)
combs_wide$p = rep(c('***',"*","ns"),3)
#plot
p +
geom_point(data=combs_long,aes(x = language,color=probability,shape=probability,y=y_pos),inherit.aes = T,position=pd,size=2) +
geom_text(data=combs_wide,label=p,y=y_pos+.025,group=X1),color='black',position=position_dodge(.75),inherit.aes = F)
我无法实现的是在group
的每个级别内绘制一条连接language
的每个对比度的线,这是注释显着的逐组差异时的标准。任何帮助,不胜感激!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)