Browse Source

Cambiar sistema de estadística a rstatix y ggpubr

stats
Costa 3 years ago
parent
commit
becbc582a1
1 changed files with 19 additions and 18 deletions
  1. +19
    -18
      app.R

+ 19
- 18
app.R

@ -122,17 +122,13 @@ server <- function(input, output) {
dades$maps<<-t_maps
}else{
if (input$test == "T-test (adj Holm)"){
t_stats<-multi_stats(t, "value", "variable", "Groups", stat.test = "ttest")
t_stats<-t %>% rename("Condition"="variable") %>% group_by(Condition) %>% t_test(value~Groups)
}
if (input$test == "Wilcoxon (adj Holm)"){
t_stats<-multi_stats(t, "value", "variable", "Groups", stat.test = "wilcox")
t_stats<-t %>% rename("Condition"="variable") %>% group_by(Condition) %>% wilcox_test(value~Groups)
}
dades$stats<<-t_stats
t_stats<-t_stats %>% filter(p.signif != "ns")
t_maps<-generate_labstats(t_stats, t, "value", "variable", "Groups")
dades$maps<<-t_maps
}
if (length(unique(dades$taula %>% pull(Groups))) < 2){
dades$stats<<-null
@ -148,7 +144,7 @@ server <- function(input, output) {
need(exists("mock_mean"), "No se puede elegir positividad con múltiples mocks")
)
if (exists("mock_mean")){
ggplot(melt(t_substr, id=ids), aes(variable, value))+
g<-ggplot(melt(t_substr, id=ids), aes(variable, value))+
labs(x="", y="Spots/2.5*10^5 cells")+
# geom_errorbar(stat="summary", position=position_dodge(width=0.9), width=0.5, aes(fill=Groups))+
geom_hline(data=mock_mean, aes(color=Groups, yintercept = `.`))+
@ -165,7 +161,7 @@ server <- function(input, output) {
}else{
ids=c("Mice", "Groups", c(ctrl, mock)[c(ctrl, mock) %in% colnames(t_substr)])
ggplot(melt(t_substr, id=ids), aes(variable, value))+
g<-ggplot(melt(t_substr, id=ids, variable.name = "Condition"), aes(Condition, value))+
labs(x="", y="Spots/2.5*10^5 cells")+
# geom_errorbar(stat="summary", position=position_dodge(width=0.9), width=0.5, aes(fill=Groups))+
# geom_bar(stat="summary", position="dodge", color="black", aes(fill=Groups))+
@ -173,11 +169,17 @@ server <- function(input, output) {
geom_jitter(position=position_jitterdodge(jitter.width = 0.2), shape=21, aes(fill=Groups), size=3)+
# geom_quasirandom(width=0.2, position=position_dodge(), shape=21)+
scale_x_discrete(limits=colnames(t_substr)[!colnames(t_substr) %in% c("Mice", "Groups", ctrl, mock)])+
geom_segment(data=t_maps$brackets, aes(x=x1, xend=x2, y=y1, yend=y2), color="black")+
geom_text(data=t_stats, aes(t_maps$label$x, t_maps$label$y, label=p.signif), color="black")+
# geom_segment(data=t_maps$brackets, aes(x=x1, xend=x2, y=y1, yend=y2), color="black")+
# geom_text(data=t_stats, aes(t_maps$label$x, t_maps$label$y, label=p.signif), color="black")+
theme_bw()+
theme(axis.text.x=element_text(angle=45, hjust=1))
}
if (input$showstats == T){
stat.pos<-t_stats %>% add_xy_position(x="Condition", step.increase = 0.06, dodge = 0.75)
g+stat_pvalue_manual(stat.pos,hide.ns = T)
}else{
g
}
}
})
@ -207,12 +209,11 @@ server <- function(input, output) {
if (!is.null(dades$final)){
print(dades$stats)
t_substr<-dades$final
t_stats<-dades$stats %>% filter(p.signif != "ns")
t_maps<-dades$maps
t_stats<-dades$stats
ids<-c("Mice", "Groups")
set.seed(123)
g<-ggplot(melt(t_substr, id=ids), aes(variable, value))+
g<-ggplot(melt(t_substr, id=ids, variable.name="Condition"), aes(Condition, value))+
labs(x="", y="Spots/2.5*10^5 cells")+
geom_boxplot(color="black", aes(fill=Groups), alpha=0.4, outlier.alpha = 0, position=position_dodge(width=0.8),width=input$`boxplot-width`)+
geom_jitter(position=position_jitterdodge(jitter.width = 0.2), shape=21, aes(fill=Groups), size=input$`point-size`)+
@ -227,13 +228,13 @@ server <- function(input, output) {
g<-g+theme_gray(base_size = input$`font-size`)
}
g<-g+theme(axis.text.x=element_text(angle=45, hjust=1))
if (input$stats2 == T){
g<-g+geom_segment(data=t_maps$brackets, aes(x=x1, xend=x2, y=y1, yend=y2), color="black")+
geom_text(data=t_stats, aes(t_maps$label$x, t_maps$label$y, label=p.signif), color="black")
}
if (input$legend == F){
g<-g+guides(color=FALSE, fill=FALSE)
}
if (input$stats2 == T){
stat.pos<-dades$stats %>% add_xy_position(x="Condition", step.increase = 0.06, dodge = 0.75)
g<-g+stat_pvalue_manual(stat.pos,hide.ns = T)
}
if (input$colors != ""){
v_col<-strsplit(input$colors, ",")[[1]]
g<-g+scale_color_manual(values=v_col)+

Loading…
Cancel
Save