Skip to content

Commit 538550a

Browse files
add CrI width display
1 parent 9129768 commit 538550a

File tree

11 files changed

+108
-20
lines changed

11 files changed

+108
-20
lines changed

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Authors@R:
55
c(person(given="Katja",family= "Danielzik", email="katja.danielzik@uni-due.de",
66
role = c("aut", "cre","cph"),
77
comment=c(ORCID="0009-0007-5021-6212")),
8+
person(given="Simo",family="Kitanovski",role="aut",
9+
comment=c(ORCID="0000-0003-2909-5376")),
810
person(given="Daniel",family="Hoffmann",role="aut",
911
comment=c(ORCID="0000-0003-2973-7869")))
1012
URL: https://github.com/KatjaDanielzik/BayesVolcano

R/plot_volcano.R

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' @param result from [prepare_volcano_df()] (a list with `result` and `meta`).
44
#' @param CrI Logical. Whether to display the CrI Interval of the parameter
5+
#' @param CrI.width Logical. Whether to display the CrI width as point size.
56
#' @param color Column in `result$result. Can be numerical or character.
67
#' @param label Character column name in `result$result` to use for labeling
78
#' points (e.g., "label", "parameter").
@@ -40,6 +41,7 @@
4041

4142
plot_volcano <- function(result,
4243
CrI = FALSE,
44+
CrI.width = FALSE,
4345
color = NULL,
4446
label = NULL,
4547
label.parameter.threshold = NULL,
@@ -90,6 +92,7 @@ plot_volcano <- function(result,
9092
pi.value <- NULL
9193
parameter.low <- NULL
9294
parameter.high <- NULL
95+
distance.CrI <- NULL
9396

9497
# create base plot ####
9598
## get threshold
@@ -106,6 +109,19 @@ plot_volcano <- function(result,
106109
ylab("pi")+
107110
ggtitle(title, subtitle)
108111

112+
if(CrI.width==TRUE){
113+
subtitle <- paste0(subtitle,'\n',
114+
"point size = |CrI|")
115+
p <- ggplot(df,(aes(x=parameter.median,y=pi.value))) +
116+
geom_point(aes(size=-CrI.width))+
117+
theme_bw()+
118+
# mark user set zero.effect
119+
geom_vline(aes(xintercept=t))+
120+
xlab(xlab)+
121+
ylab("pi")+
122+
ggtitle(title, subtitle)
123+
}
124+
109125
# add errorbar ####
110126
if(CrI==TRUE){
111127

@@ -119,22 +135,40 @@ plot_volcano <- function(result,
119135

120136
# add color ####
121137
if(!is.null(color)){
122-
if(is.numeric(df[[color]])){
123-
temp <- as.symbol(color)
124-
temp <- enquo(temp)
125-
p <- p+
126-
geom_point(aes(col = !!temp))+
127-
scale_color_viridis_c()
128-
}
129-
if(is.character(df[[color]])){
138+
if(CrI.width==FALSE){
139+
if(is.numeric(df[[color]])){
130140
temp <- as.symbol(color)
131141
temp <- enquo(temp)
132142
p <- p+
133143
geom_point(aes(col = !!temp))+
134-
scale_color_viridis_d()
144+
scale_color_viridis_c()
145+
}
146+
if(is.character(df[[color]])){
147+
temp <- as.symbol(color)
148+
temp <- enquo(temp)
149+
p <- p+
150+
geom_point(aes(col = !!temp))+
151+
scale_color_viridis_d()
152+
}
153+
}
154+
if(CrI.width==TRUE){
155+
if(is.numeric(df[[color]])){
156+
temp <- as.symbol(color)
157+
temp <- enquo(temp)
158+
p <- p+
159+
geom_point(aes(col = !!temp,size=-CrI.width))+
160+
scale_color_viridis_c()
161+
}
162+
if(is.character(df[[color]])){
163+
temp <- as.symbol(color)
164+
temp <- enquo(temp)
165+
p <- p+
166+
geom_point(aes(col = !!temp,size=-CrI.width))+
167+
scale_color_viridis_d()
168+
}
169+
135170
}
136171
}
137-
138172
# add label ####
139173
if(!is.null(label)){
140174
# make useable for ggplot

R/prepare_volcano_df.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#' \item \code{parameter.median}: median posterior parameter value
3131
#' \item \code{parameter.low}: lower boundary of CrI of parameter value
3232
#' \item \code{paramter.high}: upper boundary of CrI of parameter value
33+
#' \item \code{CrI.width}: the absolute distance parameter.low and parameter.high
3334
#' \item \code{label}: biological label (e.g., `cell.line`)
3435
#' \item Other columns from `annotation_df` (e.g., `group`, `condition`)
3536
#' }
@@ -122,14 +123,17 @@ prepare_volcano_df <- function(
122123
median_val <- median(values)
123124
crI_low <- stats::quantile(values, probs = CrI.low, na.rm = TRUE)
124125
crI_high <- stats::quantile(values, probs = CrI.high, na.rm = TRUE)
126+
CrI_width <- .CrI.width(CrI.low = crI_low, CrI.high = crI_high)
127+
128+
# Return as data frame
125129

126-
# Return as list
127130
return(as.data.frame(cbind(
128131
parameter = param,
129132
pi.value = pi_value,
130133
parameter.median = median_val,
131134
parameter.low = crI_low,
132-
parameter.high = crI_high
135+
parameter.high = crI_high,
136+
CrI.width = CrI_width
133137
)))
134138
})
135139

@@ -145,6 +149,7 @@ prepare_volcano_df <- function(
145149
result$parameter.median <- as.numeric(result$parameter.median)
146150
result$parameter.low <- as.numeric(result$parameter.low)
147151
result$parameter.high <- as.numeric(result$parameter.high)
152+
result$CrI.width <- as.numeric(result$CrI.width)
148153

149154
return(list(result=result,meta=list(CrI.low=as.numeric(CrI.low),
150155
CrI.high=as.numeric(CrI.high),

R/utils.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@
1111
l <- length(value)
1212
pi <- 2*max(sum(value<=zero.effect)/l, sum(value>=zero.effect)/l)-1
1313
return(pi)
14+
}
15+
16+
#' CrI width
17+
#'
18+
#' @param CrI.low lower bound of credible interval
19+
#' @param CrI.high upper bound of credible interval
20+
#'
21+
#' @returns absolute distance between CrI and zero effect
22+
#' @keywords internal
23+
.CrI.width <- function(CrI.low, CrI.high){
24+
d.CrI <- abs(CrI.high-CrI.low)
1425
}

man/dot-CrI.width.Rd

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
10.7 KB
Loading
3.15 KB
Loading

man/plot_volcano.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prepare_volcano_df.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-prepare_volcano_df.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ test_that("Left join with annotation_df preserves additional columns", {
214214

215215
expect_equal(names(result$result), c(
216216
"parameter", "pi.value", "parameter.median", "parameter.low", "parameter.high",
217-
"label", "group", "condition"
217+
"CrI.width","label", "group", "condition"
218218
))
219219
})
220220

0 commit comments

Comments
 (0)