I’m trying to generate a ternary plot with contour inside, my variable conc1, conc2, conc3 in term of ZIP, but I want to plot the absolute on the sides of the triangle, however, my code plot these values in uneven spacing:
I want to plot something similar this while keeping the absolute values.
This my data structure:
tibble [125 × 14] (S3: tbl_df/tbl/data.frame)
$ block_id : num [1:125] 1 1 1 1 1 1 1 1 1 1 ...
$ conc1 : num [1:125] 0 0.3 0.15 0.075 0.0375 0 0.3 0.15 0.075 0.0375 ...
$ conc2 : num [1:125] 0 0.05 0.05 0.05 0.05 0.05 0.025 0.025 0.025 0.025 ...
$ conc3 : num [1:125] 0 0 0 0 0 0 0 0 0 0 ...
$ ZIP_fit : num [1:125] 2.03 93.37 90.1 77.32 72.86 ...
$ ZIP_ref : num [1:125] 2.03 89.87 69.93 52.5 43.38 ...
$ ZIP_synergy : num [1:125] 0 3.5 20.2 24.8 29.5 ...
$ HSA_ref : num [1:125] 2.03 85.48 51.92 38.55 40.02 ...
$ HSA_synergy : num [1:125] 0 6.99 40.32 38.11 34.54 ...
$ Loewe_ref : num [1:125] 2.03 84.81 53.22 35.13 20.92 ...
$ Loewe_synergy: num [1:125] 0 7.66 39.02 41.53 53.64 ...
$ Loewe_ci : num [1:125] NA 0.658 0.349 0.306 0.161 ...
$ Bliss_ref : num [1:125] 2.03 91.22 70.65 56.03 46.33 ...
$ Bliss_synergy: num [1:125] 0 1.26 21.59 20.64 28.23 ...
this is my data (head part):
# A tibble: 6 × 14
block_id conc1 conc2 conc3 ZIP_fit ZIP_ref ZIP_synergy HSA_ref HSA_synergy
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 0 0 0 2.03 2.03 0 2.03 0
2 1 0.3 0.05 0 93.4 89.9 3.50 85.5 6.99
3 1 0.15 0.05 0 90.1 69.9 20.2 51.9 40.3
4 1 0.075 0.05 0 77.3 52.5 24.8 38.6 38.1
5 1 0.0375 0.05 0 72.9 43.4 29.5 40.0 34.5
6 1 0 0.05 0 38.6 38.6 0 38.6 0
# ℹ 5 more variables: Loewe_ref <dbl>, Loewe_synergy <dbl>, Loewe_ci <dbl>,
# Bliss_ref <dbl>, Bliss_synergy <dbl>
this is my code:
library(ggtern)
library(dplyr)
library(readxl)
conc1_values <- c(0, 0.3, 0.15, 0.075, 0.0375)
conc2_values <- c(0, 0.05, 0.025, 0.0125, 0.00625)
conc3_values <- c(0, 1, 0.5, 0.25, 0.125)
eff_data <- read_xlsx("/Users/triple.xlsx")
head(eff_data)
str(eff_data)
expanded_data <- expand.grid(conc1 = conc1_values, conc2 = conc2_values, conc3 = conc3_values)
eff_data <- merge(expanded_data, eff_data, by = c("conc1", "conc2", "conc3"))
ggtern(data = eff_data, mapping = aes(x = conc1, y = conc2, z = conc3)) +
stat_density_tern(geom = 'polygon', n = 400, bdl = 0.01,
aes(fill = ..level.., alpha = ..level..)) +
geom_point(size = 2, color = "black") +
scale_fill_gradient(low = "blue", high = "red", name = "",
breaks = 1:5, labels = c("low", "", "", "", "high")) +
scale_L_continuous(breaks = conc1_values, labels = round(conc1_values, 4)) +
scale_R_continuous(breaks = conc2_values, labels = round(conc2_values, 4)) +
scale_T_continuous(breaks = conc3_values, labels = round(conc3_values, 4)) +
labs(title = "Density plot") +
guides(fill = guide_colorbar(order = 2), alpha = guide_none()) +
theme_rgbg() +
theme_noarrows() +
theme(legend.justification = c(0, 1), legend.position = c(0, 1))
4