rm(list = ls())
###############################input data
dir_path <- "C:/Users/liyix/OneDrive/Desktop/"
dir_path_name <- dir(dir_path,pattern = "results.xlsx")
dir_path_name #[1] "results.xlsx"
## [1] "results.xlsx"
##############################signal input
library(openxlsx)
dir_path_file <- paste0(dir_path,dir_path_name)
object_file <- read.xlsx(dir_path_file)
library(tidyverse)
## -- Attaching packages ----------------------------------------------------------- tidyverse 1.3.0 --
## √ ggplot2 3.3.2 √ purrr 0.3.4
## √ tibble 3.0.3 √ dplyr 1.0.1
## √ tidyr 1.1.2 √ stringr 1.4.0
## √ readr 1.3.1 √ forcats 0.5.0
## -- Conflicts -------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
########
object_file_1 <- gather(object_file,key = "key", value = "value", -c(1,2))
object_file_1$value <- gsub("±.*", "", object_file_1$value)
###############################
object_file_1$value <- as.numeric(object_file_1$value)
colnames(object_file_1) <- gsub("key", "Evaluation_parameter",colnames(object_file_1))
#plot
object_file_1$model <- paste0(object_file_1$model, "-", object_file_1$Evaluation_parameter)
object_file_1$model <- gsub("_.*", "", object_file_1$model)
object_file_1$Evaluation_parameter <- gsub(".*_", "", object_file_1$Evaluation_parameter)
head(object_file_1,10)
## organ model Evaluation_parameter value
## 1 Behavioral NB-A auc 0.59
## 2 Behavioral NNET-A auc 0.57
## 3 Behavioral RF-A auc 0.62
## 4 Behavioral SVM-A auc 0.62
## 5 Blood NB-A auc 0.66
## 6 Blood NNET-A auc 0.67
## 7 Blood RF-A auc 0.62
## 8 Blood SVM-A auc 0.64
## 9 Brain And Coverings NB-A auc 0.62
## 10 Brain And Coverings NNET-A auc 0.58
###DRAW PLOT
ggplot(data=object_file_1, aes(x=model, y=value, group=Evaluation_parameter)) +
geom_line(linetype="dashed", aes(color=Evaluation_parameter), size=0.5)+
geom_point(aes(color=Evaluation_parameter), size=2) +
theme(legend.position = "top",
legend.background = element_rect(fill="gray95", size=.5, linetype="dotted"),
panel.background = element_rect(fill = NA, colour = "black",size = 1,linetype = "solid"),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(colour = "grey90",linetype="dotted"),
panel.grid.minor = element_blank(),
strip.background = element_blank(),
strip.text.x = element_text(size=10, angle=0),
strip.text.y = element_blank(),
strip.placement = "outside",
panel.spacing = unit(0.2, "lines"),
axis.title.x = element_blank(),
axis.text = element_text(color="black", size=10, face="plain"),
axis.text.x = element_text(color="black", size=10, face="plain", angle = 90, hjust = 1,vjust = 0.3),
plot.title = element_text(hjust = 0.5,color="black", size= 10, face="bold"),
axis.ticks.length = unit(.15, "cm"),
axis.ticks.x= element_line(size = 1),
axis.ticks.y= element_line(size = 1)) +
scale_y_continuous(expand = c(0.01,0.01)) +
labs(title= "",x="", y = "Optimal performance value") +
guides(color=guide_legend("Evaluation parameter"))+
facet_wrap( organ ~., ncol=2)

#output
ggsave(filename = paste0(Sys.Date(),"-stat_chart_coord_1.tif"), plot = last_plot(),
device = "tiff", path = dir_path,
scale = 1, width = 18, height = 16, units = "cm",dpi = 300, limitsize = TRUE, compression = "lzw")