Skip to content

supporting the main plot with coord_fixed#45

Merged
GuangchuangYu merged 2 commits intoYuLab-SMU:masterfrom
xiangpin:master
Feb 19, 2025
Merged

supporting the main plot with coord_fixed#45
GuangchuangYu merged 2 commits intoYuLab-SMU:masterfrom
xiangpin:master

Conversation

@xiangpin
Copy link
Member

  • This pr update the method of accessors
  • updating the internal function to support the main plot with coord_fixed
    • this feature can be used to visualize the result of spatial omics.
{library(aplot)
library(SpatialExperiment)
library(SingleCellExperiment)
library(SVP)
library(ggsc)
library(ggplot2)
library(STexampleData)
library(scater)
} |> suppressPackageStartupMessages()


spe <- STexampleData::Visium_humanDLPFC()

spe <- spe[,!is.na(spe$ground_truth)]

spe <- spe[rowSums(counts(spe)>0)>0,]
spe <- spe |> logNormCounts()

#spe <- runDetectSVG(spe)
#svDf(spe) |> dplyr::arrange(rank) |> head()

p1 <- spe |> sc_spatial(
         features='ENSG00000197971',
         mapping = aes(x= pxl_row_in_fullres, y = pxl_col_in_fullres),
         geom=geom_bgpoint,pointsize=1.5, image.plot=F, slot=2
         ) +
       ggtitle(NULL)

da <- p1$data |>
    dplyr::select(pxl_col_in_fullres, pxl_row_in_fullres, ground_truth)

theme_subplot <- list(xlab(NULL),
                      ylab(NULL),
                      theme_bw(),
                      theme(panel.grid=element_blank()
                      )
)

p.t <- da |>
    dplyr::mutate(row=round(pxl_row_in_fullres)) |>
    dplyr::group_by(row, ground_truth) |>
    dplyr::summarize(row_prop=100*dplyr::n()/nrow(da)) |>
    ggplot(aes(x=row,y=ground_truth,fill=ground_truth, alpha=row_prop)) +
    geom_tile() +
    theme_subplot +
    guides(x = 'none') +
    scale_fill_brewer(palette = 'Set2')


p.r <- da |>
    dplyr::mutate(col=round(pxl_col_in_fullres)) |>
    dplyr::group_by(col, ground_truth) |>
    dplyr::summarize(col_prop=100*dplyr::n()/nrow(da)) |>
    ggplot(aes(y=col,x=ground_truth,fill=ground_truth, alpha=col_prop)) +
    geom_tile() +
    theme_subplot +
    guides(y='none',x=guide_axis(angle=-45)) +
    scale_fill_brewer(palette='Set2')


pp <- p1 |> insert_top(p.t, height=.2) |> insert_right(p.r, width=.23)

image

@GuangchuangYu GuangchuangYu merged commit 0e9223d into YuLab-SMU:master Feb 19, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants