I have my code (model) in R:
library(ggplot2)
V <- function(c, E, HS, EC_50) E / (1 exp(HS * (c - EC_50)))
HS <- 1
log_EC50 <- log(1e-3)
E <- 0
log_c <- seq(-12, 0, by = 0.1)
df <- data.frame(log_c = log_c, response = V(log_c, E, HS, log_EC50))
ggplot(df, aes( response)) geom_histogram(binwidth=0.03)
I want to create a function that will draw a histogram just like in my code but will take into account changes in parameters, e.g. HS, E.
Please help
CodePudding user response:
Just wrap ggplot
into function, like:
library(ggplot2)
log_c <- seq(-12, 0, by = 0.1)
E <- 1
HS <- 1
log_EC50 <- log(1e-3)
V <- function(c, E, HS, EC_50) {
E / (1 exp(HS * (c - EC_50)))
}
a <- function(log_c, E, HS, log_EC_50) {
df <- data.frame(log_c = {{log_c}}, response = V({{log_c}}, {{E}}, {{HS}}, {{log_EC50}}))
ggplot2::ggplot(df, aes( response)) geom_histogram(binwidth=0.03)
}
a(log_c, E=1, HS=2, log_EC50)
a(log_c, E=1, HS=5, log_EC50)
Created on 2022-10-29 with reprex v2.0.2