library(Seurat)
## Attaching SeuratObject
library(SeuratData)
## ── Installed datasets ───────────────────────────────────── SeuratData v0.2.2 ──
## ✓ ifnb    3.1.0                         ✓ pbmcsca 3.0.0
## ✓ panc8   3.0.2
## ────────────────────────────────────── Key ─────────────────────────────────────
## ✓ Dataset loaded successfully
## > Dataset built with a newer version of Seurat than installed
## ❓ Unknown version of Seurat installed
library(SeuratWrappers)
library(SeuratObject)
library(ggplot2)
library(devtools)
## Loading required package: usethis
library(ggpubr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
lastone <- readRDS("/mnt/nectar_volume/home/eraz0001/new/alberto final files/lastone.rds")
head(lastone)
##                                    orig.ident nCount_RNA nFeature_RNA
## C1L_C1L_AAACCCAAGACCTGGA-1_1_1_1_1        C1L       5447         1683
## C1L_C1L_AAACCCACAATACCCA-1_1_1_1_1        C1L       8203         2268
## C1L_C1L_AAACCCACAGTACTAC-1_1_1_1_1        C1L       3869         1309
## C1L_C1L_AAACCCAGTTATGGTC-1_1_1_1_1        C1L       9335         2557
## C1L_C1L_AAACCCAGTTGAGAGC-1_1_1_1_1        C1L       2544         1060
## C1L_C1L_AAACCCAGTTGCTCAA-1_1_1_1_1        C1L      13549         3026
## C1L_C1L_AAACCCATCAACTCTT-1_1_1_1_1        C1L       6375         1843
## C1L_C1L_AAACGAAAGCTTGTGT-1_1_1_1_1        C1L       2104          953
## C1L_C1L_AAACGAAAGGTGCTAG-1_1_1_1_1        C1L       3107         1218
## C1L_C1L_AAACGAAAGTCCGCCA-1_1_1_1_1        C1L        991          512
##                                    RNA_snn_res.0.8 seurat_clusters nCount_SCT
## C1L_C1L_AAACCCAAGACCTGGA-1_1_1_1_1               6               3       3033
## C1L_C1L_AAACCCACAATACCCA-1_1_1_1_1              11              17       3269
## C1L_C1L_AAACCCACAGTACTAC-1_1_1_1_1               3               4       3257
## C1L_C1L_AAACCCAGTTATGGTC-1_1_1_1_1               2               1       3217
## C1L_C1L_AAACCCAGTTGAGAGC-1_1_1_1_1               4              10       2640
## C1L_C1L_AAACCCAGTTGCTCAA-1_1_1_1_1               3               2       2936
## C1L_C1L_AAACCCATCAACTCTT-1_1_1_1_1               4               6       3018
## C1L_C1L_AAACGAAAGCTTGTGT-1_1_1_1_1               5               5       2844
## C1L_C1L_AAACGAAAGGTGCTAG-1_1_1_1_1               5              11       3063
## C1L_C1L_AAACGAAAGTCCGCCA-1_1_1_1_1               8               0       2271
##                                    nFeature_SCT SCT_snn_res.0.8 percent.mt
## C1L_C1L_AAACCCAAGACCTGGA-1_1_1_1_1         1626               3 0.00000000
## C1L_C1L_AAACCCACAATACCCA-1_1_1_1_1         1826              17 0.00000000
## C1L_C1L_AAACCCACAGTACTAC-1_1_1_1_1         1309               4 0.03944773
## C1L_C1L_AAACCCAGTTATGGTC-1_1_1_1_1         2068               1 0.00000000
## C1L_C1L_AAACCCAGTTGAGAGC-1_1_1_1_1         1060              10 0.00000000
## C1L_C1L_AAACCCAGTTGCTCAA-1_1_1_1_1         1724               2 0.00000000
## C1L_C1L_AAACCCATCAACTCTT-1_1_1_1_1         1578               6 0.00000000
## C1L_C1L_AAACGAAAGCTTGTGT-1_1_1_1_1          952               5 0.04405286
## C1L_C1L_AAACGAAAGGTGCTAG-1_1_1_1_1         1218              11 0.07049700
## C1L_C1L_AAACGAAAGTCCGCCA-1_1_1_1_1          546               0 0.00000000
##                                    nFeature_RNA_MAD nCount_RNA_MAD method
## C1L_C1L_AAACCCAAGACCTGGA-1_1_1_1_1        0.3925254     0.45828981  Chip1
## C1L_C1L_AAACCCACAATACCCA-1_1_1_1_1        0.9813830     0.98712902  Chip1
## C1L_C1L_AAACCCACAGTACTAC-1_1_1_1_1       -0.1035465     0.01646269  Chip1
## C1L_C1L_AAACCCAGTTATGGTC-1_1_1_1_1        1.2181264     1.15409935  Chip1
## C1L_C1L_AAACCCAGTTGAGAGC-1_1_1_1_1       -0.5200306    -0.52506485  Chip1
## C1L_C1L_AAACCCAGTTGCTCAA-1_1_1_1_1        1.5505464     1.63528641  Chip1
## C1L_C1L_AAACCCATCAACTCTT-1_1_1_1_1        0.5717895     0.66148816  Chip1
## C1L_C1L_AAACGAAAGCTTGTGT-1_1_1_1_1       -0.7300729    -0.77034231  Chip1
## C1L_C1L_AAACGAAAGGTGCTAG-1_1_1_1_1       -0.2457732    -0.26684183  Chip1
## C1L_C1L_AAACGAAAGTCCGCCA-1_1_1_1_1       -1.9564436    -1.74278744  Chip1
##                                      group
## C1L_C1L_AAACCCAAGACCTGGA-1_1_1_1_1 Control
## C1L_C1L_AAACCCACAATACCCA-1_1_1_1_1 Control
## C1L_C1L_AAACCCACAGTACTAC-1_1_1_1_1 Control
## C1L_C1L_AAACCCAGTTATGGTC-1_1_1_1_1 Control
## C1L_C1L_AAACCCAGTTGAGAGC-1_1_1_1_1 Control
## C1L_C1L_AAACCCAGTTGCTCAA-1_1_1_1_1 Control
## C1L_C1L_AAACCCATCAACTCTT-1_1_1_1_1 Control
## C1L_C1L_AAACGAAAGCTTGTGT-1_1_1_1_1 Control
## C1L_C1L_AAACGAAAGGTGCTAG-1_1_1_1_1 Control
## C1L_C1L_AAACGAAAGTCCGCCA-1_1_1_1_1 Control
new.cluster.ids <- c("Chondrocytes", "Hes1+", "PACs", "Pdgfra+", "Adipocytes", "NA1", "Osteoclasts",
                     "Muscle Cells", "Lepr+", "Muscle Cells", "SSPC", "HTC", 
                     "Chondrocytes", "Muscle Cells", "Osteoblasts", "Chondrocytes",
                     "Muscle Cells", "Macrophages", "Endothelial Cells", "Macrophages",
                     "Muscle Cells", "EA-Chondrocytes", "Immuno-Cells", "Fibroblasts",
                     "Muscle Cells", "MSCs")
names(new.cluster.ids) <- levels(lastone)
lastone <- RenameIdents(lastone, new.cluster.ids)
your_font_size <- 15
a <- VlnPlot(lastone, features = 'Col2a1', split.by = 'group', pt.size = 0.0, combine = T, split.plot = T, cols =c("#e31a1c", "#ffda79")) + theme_bw() + theme(legend.title = element_blank()) +
    stat_summary(fun = median, fun.min = median, fun.max = median,
                 geom = "crossbar", 
                 width = 0.6,
                 position = position_dodge(width = .70)) +   xlab("Clusters") + ylab("Gene Expression") + stat_compare_means(aes(label = ifelse(p < 1.e-4, sprintf("p = %2.1e",as.numeric(..p.format..)), sprintf("p = %5.4f", as.numeric(..p.format..)))), method = "wilcox.test", paired = T) + stat_compare_means(size = your_font_size, label = "p.signif")+theme(text = element_text(size = 20, angle = 45))+
    guides(fill = guide_legend(override.aes = list(linetype = 0)),
           color = guide_legend(override.aes = list(linetype = 0)))
## The default behaviour of split.by has changed.
## Separate violin plots are now plotted side-by-side.
## To restore the old behaviour of a single split violin,
## set split.plot = TRUE.
##       
## This message will be shown once per session.

The most common methods for comparing means include:

t.test() Compare two groups (parametric) wilcox.test() Compare two groups (non-parametric) anova() Compare multiple groups (parametric) kruskal.test() Compare multiple groups (non-parametric)

a
## Warning: Computation failed in `stat_compare_means()`:
## Problem while computing `p = purrr::map(...)`.

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.4 LTS
## 
## Matrix products: default
## BLAS:   /mnt/nectar_volume/software/apps/R/4.0.2/lib/R/lib/libRblas.so
## LAPACK: /mnt/nectar_volume/software/apps/R/4.0.2/lib/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
##  [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
##  [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] dplyr_1.0.8              ggpubr_0.4.0             devtools_2.4.3          
##  [4] usethis_2.1.5            ggplot2_3.3.6            SeuratWrappers_0.3.0    
##  [7] pbmcsca.SeuratData_3.0.0 panc8.SeuratData_3.0.2   ifnb.SeuratData_3.1.0   
## [10] SeuratData_0.2.2         SeuratObject_4.0.4       Seurat_4.1.0            
## 
## loaded via a namespace (and not attached):
##   [1] backports_1.4.1       plyr_1.8.6            igraph_1.2.11        
##   [4] lazyeval_0.2.2        splines_4.0.2         listenv_0.8.0        
##   [7] scattermore_0.7       digest_0.6.29         htmltools_0.5.2      
##  [10] fansi_1.0.2           magrittr_2.0.2        memoise_2.0.1        
##  [13] tensor_1.5            cluster_2.1.3         ROCR_1.0-11          
##  [16] remotes_2.4.2         globals_0.14.0        matrixStats_0.61.0   
##  [19] R.utils_2.11.0        spatstat.sparse_2.1-0 prettyunits_1.1.1    
##  [22] colorspace_2.0-2      rappdirs_0.3.3        ggrepel_0.9.1        
##  [25] xfun_0.30             callr_3.7.0           crayon_1.4.2         
##  [28] jsonlite_1.7.3        spatstat.data_2.1-2   survival_3.1-12      
##  [31] zoo_1.8-9             glue_1.6.1            polyclip_1.10-0      
##  [34] gtable_0.3.0          leiden_0.3.9          car_3.0-12           
##  [37] pkgbuild_1.3.1        future.apply_1.8.1    abind_1.4-5          
##  [40] scales_1.1.1          DBI_1.1.2             rstatix_0.7.0        
##  [43] miniUI_0.1.1.1        Rcpp_1.0.8            viridisLite_0.4.0    
##  [46] xtable_1.8-4          reticulate_1.24       spatstat.core_2.3-2  
##  [49] rsvd_1.0.5            htmlwidgets_1.5.4     httr_1.4.2           
##  [52] RColorBrewer_1.1-2    ellipsis_0.3.2        ica_1.0-2            
##  [55] farver_2.1.0          pkgconfig_2.0.3       R.methodsS3_1.8.1    
##  [58] sass_0.4.0            uwot_0.1.11           deldir_1.0-6         
##  [61] utf8_1.2.2            labeling_0.4.2        tidyselect_1.1.2     
##  [64] rlang_1.0.2           reshape2_1.4.4        later_1.3.0          
##  [67] munsell_0.5.0         tools_4.0.2           cachem_1.0.6         
##  [70] cli_3.2.0             generics_0.1.2        broom_0.7.12         
##  [73] ggridges_0.5.3        evaluate_0.15         stringr_1.4.0        
##  [76] fastmap_1.1.0         yaml_2.2.2            goftest_1.2-3        
##  [79] processx_3.5.2        knitr_1.39            fs_1.5.2             
##  [82] fitdistrplus_1.1-6    purrr_0.3.4           RANN_2.6.1           
##  [85] pbapply_1.5-0         future_1.23.0         nlme_3.1-148         
##  [88] mime_0.12             ggrastr_1.0.1         R.oo_1.24.0          
##  [91] brio_1.1.3            compiler_4.0.2        rstudioapi_0.13      
##  [94] beeswarm_0.4.0        plotly_4.10.0         png_0.1-7            
##  [97] ggsignif_0.6.3        testthat_3.1.2        spatstat.utils_2.3-0 
## [100] tibble_3.1.6          bslib_0.3.1           stringi_1.7.6        
## [103] highr_0.9             ps_1.6.0              desc_1.4.0           
## [106] lattice_0.20-41       Matrix_1.4-0          vctrs_0.3.8          
## [109] pillar_1.7.0          lifecycle_1.0.1       BiocManager_1.30.16  
## [112] spatstat.geom_2.3-1   lmtest_0.9-39         jquerylib_0.1.4      
## [115] RcppAnnoy_0.0.19      data.table_1.14.2     cowplot_1.1.1        
## [118] irlba_2.3.5           httpuv_1.6.5          patchwork_1.1.1      
## [121] R6_2.5.1              promises_1.2.0.1      KernSmooth_2.23-17   
## [124] gridExtra_2.3         vipor_0.4.5           parallelly_1.30.0    
## [127] sessioninfo_1.2.2     codetools_0.2-16      pkgload_1.2.4        
## [130] MASS_7.3-51.6         assertthat_0.2.1      rprojroot_2.0.2      
## [133] withr_2.4.3           sctransform_0.3.3     mgcv_1.8-31          
## [136] parallel_4.0.2        grid_4.0.2            rpart_4.1-15         
## [139] tidyr_1.2.0           rmarkdown_2.14        carData_3.0-5        
## [142] Rtsne_0.15            shiny_1.7.1           ggbeeswarm_0.6.0