rm(list = ls())
################# ##############input data
dir_path <- "C:\\Users\\liyix\\OneDrive\\Desktop\\"
dir_path_name <- dir(dir_path,pattern = "*.",full.names = T )
library(openxlsx)
getSheetNames(grep("data.xlsx", dir_path_name, value = T))
## [1] "Sheet1"
data_1 <- read.xlsx(grep("data.xlsx", dir_path_name, value = T), sheet = 1)
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.4.0 √ forcats 0.5.0
## Warning: package 'readr' was built under R version 4.0.3
## -- Conflicts -------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
data_2 <- gather(data_1, key = key, value = value, - c(1,10))
data_3 <- data_2[-grep("50", data_2$key), ]
###############################################
pp <- data_3[data_3$category == "A", ]
pp$key <- gsub("efficacy.\\(%\\)_inhibition", "AA", pp$key)
pp$key <- gsub("efficacy.\\(%\\)_INHIBITOR_counter", "BB", pp$key)
pp$key <- gsub("efficacy.\\(%\\)_CPE", "CC", pp$key)
pp$key <- gsub("CC_COUNTER", "DD", pp$key)
##################################
pp$key <- factor(pp$key, levels = c("DD","CC","BB","AA"))
pp
## NCGC.ID category key value
## 11 NCGC00104449-01 A AA -104.35
## 12 NCGC00488679-01 A AA -76.32
## 13 NCGC00522170-01 A AA -92.76
## 14 NCGC00599688-01 A AA -76.62
## 15 NCGC00685299-01 A AA -100.55
## 31 NCGC00104449-01 A BB 22.18
## 32 NCGC00488679-01 A BB -18.41
## 33 NCGC00522170-01 A BB 0.00
## 34 NCGC00599688-01 A BB 0.00
## 35 NCGC00685299-01 A BB 23.90
## 51 NCGC00104449-01 A CC 115.39
## 52 NCGC00488679-01 A CC 89.61
## 53 NCGC00522170-01 A CC 101.36
## 54 NCGC00599688-01 A CC 85.52
## 55 NCGC00685299-01 A CC 94.94
## 71 NCGC00104449-01 A DD 0.00
## 72 NCGC00488679-01 A DD 0.00
## 73 NCGC00522170-01 A DD 0.00
## 74 NCGC00599688-01 A DD 0.00
## 75 NCGC00685299-01 A DD -17.77
ggplot(data = pp, aes(x = NCGC.ID, y = key)) +
geom_tile(aes(fill = value), colour = "gray70",size = 0.8) +
scale_x_discrete(expand = c(0.12,0.12))+
scale_y_discrete(expand = c(0.2,0.2)) +
#coord_fixed(ratio=1) +
theme(plot.margin=unit(c(1,1,1.5,1.2),"cm"),
legend.position = c(0.5,1.05),
legend.direction = "horizontal",
panel.background = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_text(colour="black",size=10,face="plain",family = "sans",
hjust = 1, margin = margin(l = 10, r = -2)),
axis.text.x = element_text(colour="black",size=10,face="plain",family = "sans",
angle = 45, vjust = 1.2, hjust = 1),
axis.title = element_blank(),
legend.background = element_blank(),
legend.key = element_rect(colour = NA, fill = NA)) +
scale_fill_gradient2(low="darkgreen", high="darkred", guide="colorbar", name = "Efficacy (%)") +
guides(fill = guide_colourbar(title.position = "left",
title.hjust = 1,
title.vjust = 0.8,
label.position = "bottom"))

ggsave(filename = paste0(Sys.Date(),"-","pp.tif"),
plot = last_plot(), device = "tiff", path = dir_path,
width = 10, height = 12, units = "cm",
dpi = 300, limitsize = TRUE,compression = "lzw")
#