rm(list = ls())
###############################input data
dir_path <- "C:\\Users\\liyix\\OneDrive\\Desktop\\"
files_list <- dir(dir_path, pattern = "*.csv",full.names = T, recursive = F)
files_list
## [1] "C:\\Users\\liyix\\OneDrive\\Desktop\\data.csv"
#################################################data_1
data_1 <- read.csv(grep("data.csv",files_list,value = T),header = T,stringsAsFactors = F)
dim(data_1) #[1] 127 6
## [1] 127 6
length(unique(data_1$Sample.ID)) #127
## [1] 127
unique(data_1$label)
## [1] "Inhibitor" "Non-inhibitor"
data_1 <- data_1[data_1$label == "Inhibitor", ]
data_1 <- data_1[data_1$AC50..uM < 2, ]
dim(data_1) #[1] 14 6
## [1] 12 6
####################################################
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.6 v dplyr 1.0.4
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## Warning: package 'tidyr' was built under R version 4.0.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library('ggsci')
## Warning: package 'ggsci' was built under R version 4.0.5
#View(data_1)
#head(data_1)
#dim(data_1)
colnames(data_1)
## [1] "Sample.ID" "AC50..uM" "Efficacy" "AC50..uM_sd" "Efficacy_sd"
## [6] "label"
data_1$Sample.ID <- gsub("-.*", "", data_1$Sample.ID)
data_1$Sample.ID <- factor(data_1$Sample.ID, levels = data_1[order(data_1$AC50..uM),]$Sample.ID)
data_1$Sample.ID <- LETTERS[1:12]
p1 <- ggplot(data_1, aes(y=Sample.ID, x = AC50..uM, color = Sample.ID)) +
#geom_bar(position=position_dodge(0.9), stat="identity",
#colour="red", # Use black outlines
# fill=NA,
# size=0.5) + # Thinner lines
geom_point(size= 2,
position = "identity") +
geom_errorbar(aes(xmin=AC50..uM - AC50..uM_sd, xmax=AC50..uM + AC50..uM_sd, color = Sample.ID),
width=.05,position = "identity")+
ylab("") +
xlab(expression(paste(IC[50], " (μM)"))) +
ggtitle("") +
theme(legend.position = "none",
#legend.direction = "vertical",
#legend.spacing.x = unit(1, 'cm'),
#legend.spacing.y = unit(0.1, 'cm'),
#legend.title.align = 0.1,
legend.key.size = unit(.9, "cm"),
legend.text = element_text(colour="black", size=12,
face="plain"),
# legend.title = element_text(colour="red", size=10,
# face="bold"),
#legend.background = element_rect(fill="lightblue",
# size=2, linetype="solid",
# colour ="blue"),
#legend.key.height=unit(1.2,"line"),
#legend.key.width=unit(1.2,"line"),
#legend.margin=margin(5,5,5,5),
#legend.justification = c(0,1),
#legend.box.margin=margin(0,0,0,0),
legend.key = element_rect(colour = NA, fill = NA),
panel.background = element_blank(),
panel.border = element_rect(colour = NA, fill= NA, size=1),
panel.grid = element_blank(),
axis.text.x = element_text(size= 12, color = "black",family = "sans",hjust = 0.5,vjust = 0.5,angle = 0),
axis.text.y = element_text(size= 12, color = "black",family = "sans",vjust = 0.5,hjust = 0.5,angle = 0),
axis.title = element_text(size=12, color = "black",family = "sans"),
axis.ticks = element_line(size= 0.5),
axis.ticks.length = unit(3, "pt"),
#axis.title=element_text(size=14,face="bold"),
axis.line = element_line(size = 0.5, colour = "black"),
aspect.ratio=1)
p1 + scale_color_manual(values=c(pal_aaas("default")(10), pal_aaas("default")(2))) +
scale_x_log10() + coord_cartesian(clip="off") +
annotation_logticks(sides = "b",
short=unit(-0.1, "cm"),
mid=unit(-0.3, "cm"), long=unit(-0.3,"cm"))

ggsave(paste0(Sys.Date(),"-ac50.tiff"),
plot = last_plot(), device = NULL, path = dir_path,
scale = 1, width = 12, height = 12, units ="cm",dpi = 300,
limitsize = TRUE,compression = "lzw")
#refhttps://stackoverflow.com/questions/54191372/log-scale-minor-tick-marks-on-outside-of-the-axis-line-with-annotation-logticks