| 12
 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
 
 | library(ropls)
 library(ggplot2)
 library(ggsci)
 library(Cairo)
 library(tidyverse)
 library(extrafont)
 loadfonts()
 
 
 data(sacurine)
 names(sacurine)
 
 
 oplsda = opls(dataMatrix, genderFc, predI = 1, orthoI = NA)
 
 loading = oplsda@scoreMN %>% as.data.frame()
 df = sacurine[["dataMatrix"]] %>% as.data.frame()
 
 cor.value = WGCNA::cor(df, loading)
 colnames(cor.value) = 'cor'
 
 cov.value = cov(df, loading)
 colnames(cov.value) = 'cov'
 
 res = cbind(cor.value, cov.value) %>% as.data.frame()
 res$col = ifelse(res$cor > 0.2,'Positive',
 ifelse(res$cor < -0.2, 'Negative','NS'))
 res$col = factor(res$col, levels = unique(res$col))
 
 p = ggplot(res, aes(cov, cor, col = col)) +
 geom_vline(xintercept = 0, linetype = 'dashed') +
 geom_hline(yintercept = 0, linetype = 'dashed') +
 geom_point(size = 2) +
 scale_color_manual(values = c('black', 'blue', 'red')) +
 labs(x = 'Cov',y = 'Corr') +
 theme_bw() +
 theme(legend.title = element_blank(),
 legend.position = c(0.8,0.3))
 
 p
 
 ggsave(p, filename = 'S-plot.pdf',
 width = 5, height = 5, device = cairo_pdf)
 
 |