Visualization Guide

Introduction

iTALK provides three visualization functions for exploring cell-cell communication:

Function Type Best For
LRPlot() Circos plot Detailed L-R pair visualization
NetView() Network graph Overall communication topology
TimePlot() Time series Dynamic changes across conditions

This vignette demonstrates customization options for each visualization.

Setup

library(iTALK)
library(dplyr)

# Create example L-R pairs data
set.seed(42)
lr_data <- data.frame(
  ligand = c("TGFB1", "VEGFA", "IL6", "CCL2", "CXCL12", "TNF", "IL1B", "PDGFA"),
  receptor = c("TGFBR1", "KDR", "IL6R", "CCR2", "CXCR4", "TNFRSF1A", "IL1R1", "PDGFRA"),
  cell_from = c("Macrophage", "Fibroblast", "T_cell", "Monocyte", "Stromal", "Macrophage", "Dendritic", "Fibroblast"),
  cell_to = c("Fibroblast", "Endothelial", "B_cell", "T_cell", "T_cell", "Neutrophil", "T_cell", "Smooth_muscle"),
  cell_from_mean_exprs = c(45, 32, 28, 55, 40, 38, 25, 42),
  cell_to_mean_exprs = c(38, 45, 22, 35, 48, 30, 42, 35),
  comm_type = c("growth_factor", "growth_factor", "cytokine", "chemokine", "chemokine", "cytokine", "cytokine", "growth_factor"),
  stringsAsFactors = FALSE
)

# Define cell colors
cell_colors <- c(
  "T_cell" = "#E41A1C",
  "Macrophage" = "#377EB8",
  "Fibroblast" = "#4DAF4A",
  "B_cell" = "#984EA3",
  "Monocyte" = "#FF7F00",
  "Stromal" = "#A65628",
  "Endothelial" = "#F781BF",
  "Dendritic" = "#999999",
  "Neutrophil" = "#66C2A5",
  "Smooth_muscle" = "#FC8D62"
)

cat("Example data preview:\n")
#> Example data preview:
print(lr_data)
#>   ligand receptor  cell_from       cell_to cell_from_mean_exprs
#> 1  TGFB1   TGFBR1 Macrophage    Fibroblast                   45
#> 2  VEGFA      KDR Fibroblast   Endothelial                   32
#> 3    IL6     IL6R     T_cell        B_cell                   28
#> 4   CCL2     CCR2   Monocyte        T_cell                   55
#> 5 CXCL12    CXCR4    Stromal        T_cell                   40
#> 6    TNF TNFRSF1A Macrophage    Neutrophil                   38
#> 7   IL1B    IL1R1  Dendritic        T_cell                   25
#> 8  PDGFA   PDGFRA Fibroblast Smooth_muscle                   42
#>   cell_to_mean_exprs     comm_type
#> 1                 38 growth_factor
#> 2                 45 growth_factor
#> 3                 22      cytokine
#> 4                 35     chemokine
#> 5                 48     chemokine
#> 6                 30      cytokine
#> 7                 42      cytokine
#> 8                 35 growth_factor

LRPlot: Circos Visualization

Basic Circos Plot

The LRPlot() function creates a circular visualization where arrows represent ligand-receptor interactions between cell types.

LRPlot(
  data = lr_data,
  datatype = "mean count",
  cell_col = cell_colors,
  transparency = 0.5,
  link.arr.lwd = 2,
  link.arr.type = "triangle"
)
Basic circos plot showing ligand-receptor interactions between cell types

Basic circos plot showing ligand-receptor interactions between cell types

Understanding the Circos Plot

The circos plot encodes multiple dimensions:

  • Outer ring: Cell types (colored sectors)
  • Inner ring: Gene names (ligands and receptors)
  • Arrows: Communication direction (ligand → receptor)
  • Arrow width: Expression level of ligand
  • Arrow head width: Expression level of receptor

Customized Circos Plot

# Custom arrow properties based on expression
LRPlot(
  data = lr_data,
  datatype = "mean count",
  cell_col = cell_colors,
  transparency = 0.3,
  link.arr.type = "big.arrow",
  track.height_1 = circlize::uh(3, "mm"),
  track.height_2 = circlize::uh(15, "mm"),
  text.vjust = "0.5cm"
)
Customized circos plot with adjusted arrow properties

Customized circos plot with adjusted arrow properties

NetView: Network Visualization

Basic Network Plot

The NetView() function creates a network graph showing overall communication patterns between cell types.

g <- NetView(
  data = lr_data,
  col = cell_colors,
  vertex.size = 30,
  vertex.label.cex = 0.8,
  edge.max.width = 8,
  edge.curved = 0.2,
  arrow.width = 1.5,
  margin = 0.2
)
Network view of cell-cell communication

Network view of cell-cell communication

Understanding the Network

  • Nodes: Cell types (size can represent number of interactions)
  • Edges: Communication channels between cells
  • Edge width: Number of L-R pairs
  • Edge color: Source cell type color
  • Arrows: Direction of communication

Customized Network with Labels

g <- NetView(
  data = lr_data,
  col = cell_colors,
  vertex.size = 35,
  vertex.label.cex = 0.9,
  vertex.label.color = "white",
  edge.max.width = 10,
  edge.curved = 0.3,
  arrow.width = 2,
  edge.label.cex = 0.7,
  edge.label.color = "darkgray",
  label = TRUE,
  margin = 0.15
)
Network plot with edge labels showing interaction counts

Network plot with edge labels showing interaction counts

DEG Data Visualization

For differential expression results, the visualization changes to show up/down regulation:

# Create DEG-style data
lr_deg <- data.frame(
  ligand = c("TGFB1", "IL6", "CCL2", "TNF"),
  receptor = c("TGFBR1", "IL6R", "CCR2", "TNFRSF1A"),
  cell_from = c("Macrophage", "T_cell", "Monocyte", "Macrophage"),
  cell_to = c("Fibroblast", "B_cell", "T_cell", "Neutrophil"),
  cell_from_logFC = c(2.5, -1.8, 1.2, 3.0),
  cell_to_logFC = c(1.8, 2.1, -0.8, 1.5),
  comm_type = c("growth_factor", "cytokine", "chemokine", "cytokine"),
  stringsAsFactors = FALSE
)
LRPlot(
  data = lr_deg,
  datatype = "DEG",
  cell_col = cell_colors,
  transparency = 0.4
)
Circos plot for DEG data showing up/down regulation

Circos plot for DEG data showing up/down regulation

Arrow color coding for DEG:

Ligand Receptor Arrow Color
↑ Up ↑ Up Red (#d73027)
↑ Up ↓ Down Yellow (#dfc27d)
↓ Down ↑ Up Purple (#9933ff)
↓ Down ↓ Down Cyan (#00ccff)

Color Recommendations

Scientific Color Palettes

# Display recommended palettes
par(mfrow = c(1, 3), mar = c(1, 1, 2, 1))

# Option 1: Set1 from RColorBrewer
pal1 <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628")
barplot(rep(1, 6), col = pal1, border = NA, main = "Set1 Palette", axes = FALSE)

# Option 2: Paired
pal2 <- c("#A6CEE3", "#1F78B4", "#B2DF8A", "#33A02C", "#FB9A99", "#E31A1C")
barplot(rep(1, 6), col = pal2, border = NA, main = "Paired Palette", axes = FALSE)

# Option 3: Dark2
pal3 <- c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E", "#E6AB02")
barplot(rep(1, 6), col = pal3, border = NA, main = "Dark2 Palette", axes = FALSE)

Publication-Ready Export

# PDF export for vector graphics
pdf("communication_circos.pdf", width = 10, height = 10)
LRPlot(lr_data, datatype = "mean count", cell_col = cell_colors)
dev.off()

# PNG export for high-resolution raster
png("communication_network.png", width = 3000, height = 3000, res = 300)
NetView(lr_data, col = cell_colors, vertex.size = 30)
dev.off()

Tips and Best Practices

  1. Limit pairs for clarity: Show top 20-30 pairs in LRPlot for readability
  2. Consistent colors: Use the same cell colors across all plots
  3. Meaningful order: Sort data by expression/significance before plotting
  4. Vector formats: Use PDF for publication-quality figures
  5. Color blindness: Consider colorblind-friendly palettes

Session Info

sessionInfo()
#> R version 4.6.0 (2026-04-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_1.2.1    igraph_2.3.2   iTALK_0.1.1    rmarkdown_2.31
#> 
#> loaded via a namespace (and not attached):
#>  [1] sass_0.4.10         generics_0.1.4      tidyr_1.3.2        
#>  [4] shape_1.4.6.1       stringi_1.8.7       hms_1.1.4          
#>  [7] digest_0.6.39       magrittr_2.0.5      evaluate_1.0.5     
#> [10] grid_4.6.0          RColorBrewer_1.1-3  circlize_0.4.18    
#> [13] fastmap_1.2.0       jsonlite_2.0.0      progress_1.2.3     
#> [16] GlobalOptions_0.1.4 purrr_1.2.2         scales_1.4.0       
#> [19] pbapply_1.7-4       randomcoloR_1.1.0.1 jquerylib_0.1.4    
#> [22] cli_3.6.6           crayon_1.5.3        rlang_1.2.0        
#> [25] withr_3.0.3         cachem_1.1.0        yaml_2.3.12        
#> [28] otel_0.2.0          Rtsne_0.17          parallel_4.6.0     
#> [31] tools_4.6.0         colorspace_2.1-2    ggplot2_4.0.3      
#> [34] curl_7.1.0          buildtools_1.0.0    vctrs_0.7.3        
#> [37] R6_2.6.1            lifecycle_1.0.5     stringr_1.6.0      
#> [40] V8_8.2.0            cluster_2.1.8.2     pkgconfig_2.0.3    
#> [43] pillar_1.11.1       bslib_0.11.0        gtable_0.3.6       
#> [46] glue_1.8.1          Rcpp_1.1.1-1.1      xfun_0.59          
#> [49] tibble_3.3.1        tidyselect_1.2.1    sys_3.4.3          
#> [52] knitr_1.51          farver_2.1.2        htmltools_0.5.9    
#> [55] maketools_1.3.2     compiler_4.6.0      prettyunits_1.2.0  
#> [58] S7_0.2.2