-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure_2.R
50 lines (43 loc) · 1.89 KB
/
Figure_2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library( tidyverse )
library( patchwork )
library( jpeg )
library( grid )
source( "misc.R" )
read_tsv( "data/tecan_values.tsv", col_types = "ccliccccdd" ) -> tecan
read_tsv( "data/plates_with_CTs.tsv" ) -> tblCT
## panel b
tecan %>%
left_join( tblCT ) %>%
mutate( CT = ifelse( CT>40, 46.5, CT ) ) %>%
filter( !is.na(CT) ) %>%
filter( plate %in% "CP00001", gene=="N", plateRemark=="2" ) %>%
mutate(well = fct_reorder(well, desc(CT))) %>%
ggplot +
geom_line( aes( x=minutes, y=absBlue-absYellow, group=well, col=CT ), size=.5 ) +
scale_color_ct() +
xlab( "incubation time [minutes]" ) +
ylab( expression( "RT-LAMP (ΔOD)" ) ) -> panel_b
panel_b
## panel c
tbl_panel_c <- tecan %>%
filter( plate == "CP00001" ) %>%
filter( ( gene=="N" & minutes == 30 ) | ( gene=="1a" & minutes==40 ) ) %>%
left_join( tblCT ) %>%
filter( !is.na(CT) ) %>%
mutate( CT = ifelse( CT>40, runif( n(), 43, 47 ), CT ) ) %>%
mutate( facet = str_c( gene, " gene, ", minutes, " min" ) )
tbl_panel_c %>%
filter(gene == "N") %>%
ggplot() +
geom_vline( xintercept = 42, col="darkgray" ) +
geom_point( aes( x = CT, y = absBlue - absYellow ), fill = "black", colour = "black", alpha = .6, shape = 21, size = 1.2 ) +
scale_x_reverse( breaks = c( 10, 20, 30, 40, 45 ), labels = c( 10, 20, 30, 40, "neg" ) ) +
xlab( "RT-qPCT (CT value)" ) +
ylab( "RT-LAMP (ΔOD)" ) -> panel_c
panel_a <- readJPEG("SVGs/Figure_2a.jpg")
#svg("SVGs/Figure_3.svg", width=20/2.54, height=14/2.54) ## gives strange light borders arround CT colorscale gradient
wrap_elements(panel = rasterGrob(panel_a, x = 0, y = 0.5, just = "left", interpolate = TRUE)) / (panel_b | panel_c) +
plot_annotation(tag_levels = "A")
#dev.off()
ggsave("SVGs/Figure_2.svg", width=20, height=14, units="cm", dpi = 300) # results in low resolution raster image (https://github.com/r-lib/svglite/issues/86)
ggsave("Figure_3.png", width=20, height=14, units="cm", dpi=300)