seurat
seurat copied to clipboard
VlnPlot seems to have incorrect shape
Hi Seurat Team,
Thanks a lot for providing all of us with such a fantastic tool. When I use the VlnPlot() function on my data to visually compare the expression levels of one gene in one cell type under two different conditions (wt vs mut) in a split violin plot, the shape of the violin plot for the mutant condition seems to be wrong. Looking at the count matrices, I would not expect a difference between the two conditions. The counts are roughly equally distributed and the number of cells under each condition is also about the same. The dots plotted by the VlnPlot() function are located exactly as I would expect them to be but the violin's shape under the mutant condition doesn't make sense to me, see Tnfrsf1a_vln_seurat.pdf below.
I re-ran the code in different R sessions and the plot always looks the same. When I imitate such a plot using seaborn.violinplot() in python on the same data, the violin's shape is as I would expect it, see Tnfrsf1a_vln_seaborn.pdf below.
I specifically see that in this very plot on this very data--not on other genes or cell types--so I cannot provide an example on a public dataset. Do you agree that this might be a bug in the plotting of the violin plot or am I missing anything and the shape is correct? If you agree, do you have a recommendation where I should start looking to fix the violin plotting?Thank you so much!
Best, Paul
R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.3.1
Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggrastr_1.0.1 ggpubr_0.4.0 ggplot2_3.3.6 LoomExperiment_1.12.0
[5] BiocIO_1.4.0 rhdf5_2.38.1 SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0
[9] Biobase_2.54.0 GenomicRanges_1.46.1 GenomeInfoDb_1.30.1 IRanges_2.28.0
[13] MatrixGenerics_1.6.0 matrixStats_0.62.0 S4Vectors_0.32.4 BiocGenerics_0.40.0
[17] Seurat_4.1.1 SeuratDisk_0.0.0.9019 sp_1.4-7 SeuratObject_4.1.0
loaded via a namespace (and not attached):
[1] backports_1.4.1 plyr_1.8.7 igraph_1.3.1 lazyeval_0.2.2
[5] splines_4.1.2 BiocParallel_1.28.3 listenv_0.8.0 scattermore_0.8
[9] digest_0.6.29 htmltools_0.5.2 fansi_1.0.3 magrittr_2.0.3
[13] memoise_2.0.1 tensor_1.5 cluster_2.1.3 ROCR_1.0-11
[17] globals_0.15.0 Biostrings_2.62.0 annotate_1.72.0 spatstat.sparse_2.1-1
[21] colorspace_2.0-3 blob_1.2.3 ggrepel_0.9.1 dplyr_1.0.9
[25] crayon_1.5.1 RCurl_1.98-1.6 jsonlite_1.8.0 genefilter_1.76.0
[29] progressr_0.10.0 spatstat.data_2.2-0 survival_3.3-1 zoo_1.8-10
[33] glue_1.6.2 polyclip_1.10-0 gtable_0.3.0 zlibbioc_1.40.0
[37] XVector_0.34.0 leiden_0.4.2 DelayedArray_0.20.0 car_3.0-13
[41] Rhdf5lib_1.16.0 future.apply_1.9.0 HDF5Array_1.22.1 abind_1.4-5
[45] scales_1.2.0 DBI_1.1.2 rstatix_0.7.0 spatstat.random_2.2-0
[49] miniUI_0.1.1.1 Rcpp_1.0.8.3 viridisLite_0.4.0 xtable_1.8-4
[53] reticulate_1.25 spatstat.core_2.4-4 bit_4.0.4 htmlwidgets_1.5.4
[57] httr_1.4.3 RColorBrewer_1.1-3 ellipsis_0.3.2 ica_1.0-2
[61] farver_2.1.0 pkgconfig_2.0.3 XML_3.99-0.9 uwot_0.1.11
[65] deldir_1.0-6 locfit_1.5-9.5 utf8_1.2.2 labeling_0.4.2
[69] tidyselect_1.1.2 rlang_1.0.2 reshape2_1.4.4 later_1.3.0
[73] AnnotationDbi_1.56.2 munsell_0.5.0 tools_4.1.2 cachem_1.0.6
[77] cli_3.3.0 generics_0.1.2 RSQLite_2.2.14 broom_0.8.0
[81] ggridges_0.5.3 stringr_1.4.0 fastmap_1.1.0 goftest_1.2-3
[85] bit64_4.0.5 fitdistrplus_1.1-8 purrr_0.3.4 RANN_2.6.1
[89] KEGGREST_1.34.0 pbapply_1.5-0 future_1.25.0 nlme_3.1-157
[93] mime_0.12 hdf5r_1.3.5 compiler_4.1.2 rstudioapi_0.13
[97] beeswarm_0.4.0 plotly_4.10.0 png_0.1-7 ggsignif_0.6.3
[101] spatstat.utils_2.3-1 tibble_3.1.7 geneplotter_1.72.0 stringi_1.7.6
[105] rgeos_0.5-9 lattice_0.20-45 Matrix_1.4-1 vctrs_0.4.1
[109] rhdf5filters_1.6.0 pillar_1.7.0 lifecycle_1.0.1 spatstat.geom_2.4-0
[113] lmtest_0.9-40 RcppAnnoy_0.0.19 data.table_1.14.2 cowplot_1.1.1
[117] bitops_1.0-7 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-20 gridExtra_2.3
[125] vipor_0.4.5 parallelly_1.31.1 codetools_0.2-18 MASS_7.3-57
[129] assertthat_0.2.1 DESeq2_1.34.0 withr_2.5.0 sctransform_0.3.3
[133] GenomeInfoDbData_1.2.7 mgcv_1.8-40 parallel_4.1.2 grid_4.1.2
[137] rpart_4.1.16 tidyr_1.2.0 carData_3.0-5 Rtsne_0.16
[141] shiny_1.7.1 ggbeeswarm_0.6.0
# load seurat object
data <- Connect("...")
data.seurat <- as.Seurat(data, features = "var_names", cells = "obs_names")
# CPM normalize, log +1 transform
data.seurat_norm <- NormalizeData(object = data.seurat, scale.factor = 1e6)
# get microglia data only
Idents(object = data.seurat_norm) <- 'level_3'
data.micro_norm <- subset(x = data.seurat_norm, idents = "Microglia")
# violin plot
cols=c("#9A3367", "#B2966B")
VlnPlot(object = data.micro_norm, features = c("Tnfrsf1a"), split.by = "mutation_status", group.by = "level_3", split.plot = TRUE, cols=cols)
Hi @paulstumpges , This is a strange behavior. If you set the split.plot = F are you able to get a normal shape for your mutant group? Or is it only observed for split violin plot? Best, Longda
Hi @longmanz, I still don't get a normal shape for the mutant group when I set split.plot = F. I attached a pdf with what it looks like then. Best, Paul Tnfrsf1a_vln_seurat_split_false.pdf
Hi, @paulstumpges
This issue is related to an noise parameter we added in the violin plot. similar issue: https://github.com/satijalab/seurat/issues/5756
In the latest develop
branch, if you set add.noise = FALSE
, then you will get the same violin plot.