This is the figure that was generated with the code below:
But I want to show data with ZIP synergy score 1 or above, like this figure:
This is the code that I used to generate the first figure, which is basically based on synergyfinder package and ggplot, I've got some help from this community and I truly appreciate it (as I'm navigating my way as a self learner), to be able to make this far, I'd like to especially thank @kat for her help:
library(synergyfinder)
library(tidyverse)
data<- read_xlsx("N+X+syn.xlsx")
head(data)
dput(data)
res <- ReshapeData(
data = data,
data_type = "inhibition",
impute = TRUE,
impute_method = NULL,
noise = TRUE,
seed = 1)
res <- CalculateSynergy(
data = res,
method = c("ZIP", "HSA", "Bliss", "Loewe"),
Emin = NA,
Emax = NA,
correct_baseline = "non")
res$drug_pairs
res <- CalculateSensitivity(
data = res,
correct_baseline = "non"
)
sensitive_columns <- c(
"block_id", "drug1", "drug2",
"ic50_1", "ic50_2",
"ri_1", "ri_2",
"css1_ic502", "css2_ic501", "css")
res$drug_pairs[, sensitive_columns]
plt <- PlotMultiDrugBar(
data = res,
plot_block = 1,
plot_value = c("response", "ZIP_synergy", "Bliss_synergy", "HSA_synergy", "Loewe_synergy"),
sort_by = "ZIP_synergy",
highlight_label_size = 4
)
plt + geom_text(data = plt[["layers"]][[1]][["data"]] %>% group_by(metric) %>%
mutate(mnm = min(value)) %>% ungroup(), # group max val!
mapping = aes(x = id, y = mnm,
label = sprintf("%.2f", value), hjust = 1),
size = rel(2.3))+
geom_bar(stat = "identity", width = 4, show.legend = FALSE) + # Wider bars
scale_fill_manual(values = c("lightblue", "red")) +
theme_minimal() %>%
theme(strip.text = element_text(face = "bold", size = rel(.8)), # facet titles
axis.text = element_text(size = rel(.75)))
This is the dput:
dput(data)
structure(list(block_id = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1), drug1 = c("X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X",
"X", "X", "X", "X", "X", "X", "X", "X", "X", "X"), drug2 = c("N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N",
"N", "N"), cell_line_name = c("A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A"), conc1 = c(0, 10,
3.333, 1.111, 0.37, 0.123, 0.041, 0.014, 0.005, 10, 3.333, 1.111,
0.37, 0.123, 0.041, 0.014, 0.005, 10, 3.333, 1.111, 0.37, 0.123,
0.041, 0.014, 0.005, 10, 3.333, 1.111, 0.37, 0.123, 0.041, 0.014,
0.005, 10, 3.333, 1.111, 0.37, 0.123, 0.041, 0.014, 0.005, 10,
3.333, 1.111, 0.37, 0.123, 0.041, 0.014, 0.005, 10, 3.333, 1.111,
0.37, 0.123, 0.041, 0.014, 0.005, 10, 3.333, 1.111, 0.37, 0.123,
0.041, 0.014, 0.005, 10, 3.333, 1.111, 0.37, 0.123, 0.041, 0.014,
0.005, 0, 0, 0, 0, 0, 0, 0, 0), conc2 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 150, 150, 150, 150, 150, 150, 150, 150, 50, 50, 50, 50,
50, 50, 50, 50, 16.67, 16.67, 16.67, 16.67, 16.67, 16.67, 16.67,
16.67, 5.56, 5.56, 5.56, 5.56, 5.56, 5.56, 5.56, 5.56, 1.85,
1.85, 1.85, 1.85, 1.85, 1.85, 1.85, 1.85, 0.62, 0.62, 0.62, 0.62,
0.62, 0.62, 0.62, 0.62, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21,
0.21, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 150, 50,
16.67, 5.56, 1.85, 0.62, 0.21, 0.07), response = c(0, 94.7124199185235,
93.1970077742489, 94.9121253949008, 92.6627816399623, 90.6942562299578,
86.7432204326113, 48.8019769163964, -2.019990126606, 99.7699471228007,
99.7643531318657, 99.8387532113004, 99.6921906488051, 99.7039380297684,
99.7800163064836, 99.7251951953212, 99.7140072134513, 99.6300973494272,
99.7033786306749, 99.7979170774754, 99.7464523608739, 99.6166717711834,
99.6837996624026, 99.6088401838745, 99.5780732337323, 99.6446417258581,
99.8689607623491, 99.7050568279554, 99.6390477349231, 99.7772193110161,
99.7945606829144, 99.7207200025732, 99.5780732337323, 99.5484250817772,
99.7190418052928, 99.6888342542441, 99.566325852769, 99.5881424174152,
99.6485575195125, 99.4751438005295, 98.9370018725885, 98.8228844575157,
98.9990951719663, 99.1876126664737, 98.7663851490729, 98.937561271682,
98.7585535617639, 98.3658553981313, 95.1935031389282, 95.5710975270365,
96.8308642855844, 97.3986543654806, 97.0109907936894, 94.7661222314989,
92.3651813222237, 61.1669344789827, 35.6409944437685, 92.832279565291,
95.5559937515121, 94.2240645099035, 93.8056339879701, 89.7701289275061,
85.7827321890825, 17.6205120459602, -15.2531350822946, 92.5413920366742,
95.9811370625674, 95.9156873686286, 95.6835367448287, 96.19930270903,
91.2323981578988, 28.2244812622281, -0.782599331797783, 100.146982111815,
99.5322025080658, 99.7486899572479, 99.293339095144, 98.126432586116,
82.4643767664774, -3.55274364277894, -8.35518486042292), conc_unit = c("μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM",
"μM", "μM", "μM", "μM", "μM", "μM", "μM", "μM")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -81L))
I've tried some functions like filter, but it failed because it can't recognize output from res.
Filter the synergy_scores
component and then filter the corresponding rows of the repsonse
component by using a semi join on "block_id", "conc1", and "conc2".
library(dplyr)
res1 <- res
res1$synergy_scores <- filter(res1$synergy_scores, ZIP_synergy>=1)
res1$response <- semi_join(res1$response, res1$synergy_scores,
by=c("block_id", "conc1", "conc2"))
plt.zip1 <- PlotMultiDrugBar(
data = res1,
plot_block = 1,
plot_value = c("response", "ZIP_synergy", "Bliss_synergy", "HSA_synergy", "Loewe_synergy"),
sort_by = "ZIP_synergy",
highlight_label_size = 4
)
plt.zip1 + geom_text(data = plt.zip1[["layers"]][[1]][["data"]] %>%
group_by(metric) %>%
mutate(mnm = min(value)) %>% ungroup(), # group max val!
mapping = aes(x = id, y = mnm,
label = sprintf("%.2f", value), hjust = 1),
size = rel(2.3))+
geom_bar(stat = "identity", width = 4, show.legend = FALSE) + # Wider bars
scale_fill_manual(values = c("lightblue", "red")) +
theme_minimal() %>%
theme(strip.text = element_text(face = "bold", size = rel(.8)), # facet titles
axis.text = element_text(size = rel(.75))) +
scale_y_continuous(lim=c())