Spaces:
Sleeping
Sleeping
File size: 21,070 Bytes
8e8619e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | create_boxplot <- function(data, x_var, y_var, col, alpha, size, ylab_text, ggtitle_text) {
p <- ggplot(data,aes_string(x = x_var, y = y_var, fill = x_var)) +
geom_boxplot(color = "black", lwd = 1, alpha = alpha) +
ggbeeswarm::geom_beeswarm(aes(text = name), dodge.width = 0.1,
cex = 0.1,
shape = 21,
size = size) +
ylab(ylab_text) +
ggtitle(paste(ggtitle_text, "", sep = "")) +
scale_fill_manual(values = unlist(col))
p
}
process_boxplot <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_boxplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(tukey_result$y.min.position), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p <- p + theme_classic() + theme(
axis.text.x = element_text(angle = 90, hjust = 1),
axis.title.x = element_blank(),
aspect.ratio = 0.75,
text = element_text(size = input$Fontsize)
)
ggplotly(p,tooltip = c("name","x"))
}
process_boxplot_diagram <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_boxplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial"
) +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)
) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize)
)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[y]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p
}
process_action_boxplot <- function(input,dataa,metainfocol,svg_path,col,output) {
withProgress(message = 'Calculation in progress', detail = 'This may take a while...', value = 1, {
startnum <- 1 + metainfocol
for (i in startnum:ncol(dataa)) {
yval <- colnames(dataa)[i]
p <- create_boxplot(dataa, input$w, dataa[[yval]], col, input$alpha, input$size, input$yAxisLabel, "")
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial"
) +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)
) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize)
)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,yval,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[yval]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
svg(paste("./svg/",colnames(dataa)[i], ".svg", sep = ""))
plot(p)
dev.off()
incProgress(1 / ncol(dataa))
Sys.sleep(0.25)
}
})
data.frame(name = colnames(dataa)[-c(1:metainfocol)], path = paste("file:/", svg_path, "/", colnames(dataa)[-c(1:metainfocol)], ".svg", sep = "")) %>% write.csv("./svg/path.csv")
output$testtext1 <- renderText({
"Finish"
})
}
create_barplot <- function(data, x_var, y_var, col, alpha, size, ylab_text, ggtitle_text) {
p <- ggplot(data, aes_string(x = x_var, y = y_var, fill = x_var)) +
geom_bar(color = "black", stat = "summary",fun = "mean",lwd = 1.2,width = 0.6) +
ylab(ylab_text) +
ggtitle(paste(ggtitle_text, "", sep = "")) +
scale_fill_manual(values = unlist(col))
p
}
process_barplot <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_barplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result,remove.bracket = TRUE,
bracket.size = 0.000001,
label = "{symbol}",
tip.length = 0,
label.size = tukey_result$size,inherit.aes = FALSE,y.position = tukey_result$y.position_barplot)
}
p <- p + theme(
axis.text.x = element_text(angle = 90, hjust = 1),
axis.title.x = element_blank(),
aspect.ratio = 0.75,
text = element_text(size = input$Fontsize)
)
ggplotly(p)
}
process_barplot_diagram <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_barplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial") +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize))
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result,remove.bracket = TRUE,
bracket.size = 0.000001,
label = "{symbol}",
tip.length = 0,
label.size = tukey_result$size,inherit.aes = FALSE,y.position = tukey_result$y.position_barplot)
}
p
}
process_action_barplot <- function(input,dataa,metainfocol,svg_path,col,output) {
withProgress(message = 'Calculation in progress', detail = 'This may take a while...', value = 1, {
startnum <- 1 + metainfocol
for (i in startnum:ncol(dataa)) {
yval <- colnames(dataa)[i]
p <- create_barplot(dataa, input$w, dataa[[yval]], col, input$alpha, input$size, input$yAxisLabel, "")
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial") +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize))
if (input$q!= "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,yval,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result,remove.bracket = TRUE,
bracket.size = 0.000001,
label = "{symbol}",
tip.length = 0,
label.size = tukey_result$size,inherit.aes = FALSE,y.position = tukey_result$y.position_barplot)
}
svg(paste("./svg/",colnames(dataa)[i], ".svg", sep = ""))
plot(p)
dev.off()
}
incProgress(1 / ncol(dataa))
Sys.sleep(0.25)
})
data.frame(name = colnames(dataa)[-c(1:metainfocol)], path = paste("file:/", svg_path, "/", colnames(dataa)[-c(1:metainfocol)], ".svg", sep = "")) %>% write.csv("./svg/path.csv")
output$testtext1 <- renderText({
"Finish"
})
}
process_violinplot <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_violinplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
if (input$q != "" &&input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[y]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p <- p + theme(
#legend.position = "none",
axis.text.x = element_text(angle = 90, hjust = 1),
axis.title.x = element_blank(),
aspect.ratio = 0.75,
text = element_text(size = input$Fontsize)
)
ggplotly(p)
# }
}
create_violinplot <- function(data, x_var, y_var, col, alpha, size, ylab_text, ggtitle_text) {
p <- ggplot(data, aes_string(x = x_var, y = y_var, fill = x_var)) +
geom_violin(adjust = 2,trim = FALSE) +
ylab(ylab_text) +
ggtitle(paste(ggtitle_text, "", sep = "")) +
scale_fill_manual(values = unlist(col))+
stat_summary(fun = "mean",geom = "crossbar",color = "black",linewidth = 0.5, width = 0.5)
p
}
process_violinplot_diagram <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_violinplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial") +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize))
if (input$q != "" &&input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[y]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p
}
process_action_violinplot <- function(input,dataa,metainfocol,svg_path,col,output) {
withProgress(message = 'Calculation in progress', detail = 'This may take a while...', value = 1, {
startnum <- 1 + metainfocol
for (i in startnum:ncol(dataa)) {
yval <- colnames(dataa)[i]
p <- create_violinplot(dataa, input$w, dataa[[yval]], col, input$alpha, input$size, input$yAxisLabel, "")
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial") +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize))
if (input$q!= "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,yval,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[yval]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
svg(paste("./svg/",colnames(dataa)[i], ".svg", sep = ""))
plot(p)
dev.off()
}
incProgress(1 / ncol(dataa))
Sys.sleep(0.25)
})
data.frame(name = colnames(dataa)[-c(1:metainfocol)], path = paste("file:/", svg_path, "/", colnames(dataa)[-c(1:metainfocol)], ".svg", sep = "")) %>% write.csv("./svg/path.csv")
output$testtext1 <- renderText({
"Finish"
})
}
process_polarplot <- function(input,yval,dataa,col) {
# if(is.na(unique(select(dataa,input$w))) != TRUE){
y <- yval %>% as.character()
p <- create_polarplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y, input$Fontsize)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result,remove.bracket = TRUE,
bracket.size = 0.000001,
label = "{symbol}",
tip.length = 0,
label.size = tukey_result$size,inherit.aes = FALSE,y.position = tukey_result$y.position_barplot)
}
plot(p)
# }
}
create_polarplot <- function(data, x_var, y_var, col, alpha, size, ylab_text, ggtitle_text, Fontsize) {
p <- ggplot(data, aes_string(x = x_var, y = y_var, fill = x_var)) +
geom_bar(color = "black", stat = "summary",fun = "mean",lwd = 1.2,width = 0.6) +
coord_polar()+
scale_fill_manual(values = unlist(col))+
labs(
x="",
y="")+
theme_minimal(10) +
theme(
axis.text.x = element_text(size = Fontsize, angle = 360,hjust=0.8),
axis.title.x = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.y = element_blank())+
easy_remove_axes()
return(p)
}
process_dotplot <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_dotplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(tukey_result$y.min.position), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p <- p + theme(
axis.title.x = element_blank(),
aspect.ratio = 0.2,
axis.text.x = element_text(angle = 90, hjust = 1),
text = element_text(size = input$Fontsize)
)
ggplotly(p,tooltip = c("name","x"))
}
create_dotplot <- function(data, x_var, y_var, col, alpha, size, ylab_text, ggtitle_text) {
p <- ggplot(data,aes_string(x = x_var, y = y_var, fill = x_var)) +
ggbeeswarm::geom_beeswarm(aes(text = name),
cex = 0.1,
shape = 21,
size = size)+stat_summary(fun = "mean",geom = "crossbar",color = "red",linewidth = 0.5, width = 0.5)+
ylab(ylab_text) +
ggtitle(paste(ggtitle_text, "", sep = "")) +
theme_classic() +
theme(aspect.ratio = 1.0)+
scale_fill_manual(values = unlist(col))
p
}
process_dotplot_diagram <- function(input,yval,dataa,col) {
y <- yval %>% as.character()
p <- create_dotplot(dataa, input$w, y, col, input$alpha, input$size, input$yAxisLabel, y)
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial"
) +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)
) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize)
)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,y,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[y]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
p
}
process_action_dotplot <- function(input,dataa,metainfocol,svg_path,col,output) {
withProgress(message = 'Calculation in progress', detail = 'This may take a while...', value = 1, {
startnum <- 1 + metainfocol
for (i in startnum:ncol(dataa)) {
yval <- colnames(dataa)[i]
p <- create_dotplot(dataa, input$w, dataa[[yval]], col, input$alpha, input$size, input$yAxisLabel, "")
p <- p + theme_prism(
base_fontface = "plain",
base_line_size = 0.9,
base_family = "Arial"
) +
scale_x_discrete(
guide = guide_prism_bracket(width = 0.1),
labels = scales::wrap_format(5)
) +
theme(
legend.position = "none",
axis.title.x = element_blank(),
aspect.ratio = 1.0,
text = element_text(size = input$Fontsize)
)
if (input$q != "" && input$pvaluecheck == TRUE) {
tukey_result <- process_tukey_result(input,yval,input$q,p,dataa,0.05,input$Fontsize)
p <- p + add_pvalue(tukey_result, remove.bracket = TRUE, bracket.size = 0.000001, label = "{symbol}", tip.length = 0,
label.size = tukey_result$size, inherit.aes = FALSE,y.position = tukey_result$y.position_boxplot) + scale_y_continuous(
limits = c(min(dataa[[yval]]), (max(tukey_result$y.position_boxplot) + max(tukey_result$y.position_boxplot) / 30))
)
}
svg(paste("./svg/",colnames(dataa)[i], ".svg", sep = ""))
plot(p)
dev.off()
incProgress(1 / ncol(dataa))
Sys.sleep(0.25)
}
})
data.frame(name = colnames(dataa)[-c(1:metainfocol)], path = paste("file:/", svg_path, "/", colnames(dataa)[-c(1:metainfocol)], ".svg", sep = "")) %>% write.csv("./svg/path.csv")
output$testtext1 <- renderText({
"Finish"
})
}
process_select_color_input <- function(input,data) {
if (length(grep(paste0(unique(as.matrix(select(data, input$w)))[1], "_selectcolor"), names(input), value = TRUE)) != 0) {
inputlist <- grep("selectcolor", names(input), value = TRUE)
for (input_name in inputlist) {
collist[str_remove_all(input_name, pattern = "_selectcolor")] <- input[[input_name]]
}
cola <<- unlist(collist)
cola <- cola[c(unique(data[[input$w]]))]
return(cola)
}
}
process_tukey_result <- function(input,yval, q,plot_obj, dataa, p_adj_threshold, Fontsize) {
yval <- gsub("`","",yval)
y <- dataa %>% pull(as.symbol(yval))
w <- dataa %>% pull(as.symbol(input$w))
tukey_result <- TukeyHSD(aov(y ~ w, data = dataa))
tukey_result <- data.frame(tukey_result$w)
a <- str_split_fixed(rownames(tukey_result), "-", 2)
colnames(a) <- c("Class1", "Class2")
tukey_result <- cbind(a, tukey_result)
maxvalue <- select(dataa,input$w,yval) %>%
group_by_(input$w) %>%
mutate(Mean = mean(!!as.symbol(yval))) %>%
ungroup() %>%
distinct(!!as.symbol(input$w),.keep_all = TRUE )
maxvalue <- max(maxvalue$Mean)
tukey_result <- filter(tukey_result, Class1 %in% q | Class2 %in% q) %>%
mutate(group2 = ifelse(Class1 == q, Class2, Class1)) %>%
mutate(group1 = paste0(q)) %>%
mutate(symbol = ifelse(p.adj < p_adj_threshold, "*", "")) %>%
select(group1, group2, p.adj, symbol) %>%
mutate(y.position_boxplot = max(dataa[[yval]])) %>%
mutate(y.position_barplot = maxvalue-maxvalue/15 ) %>%
mutate(y.min.position = min(dataa[[yval]])) %>%
mutate(size = ifelse(symbol != "*", 0, Fontsize))
return(tukey_result)
} |