Skip to content

cnetplot() error: enrichResult subset with grepl fails when color_edge="category" #802

@Sophia409

Description

@Sophia409

Description

When using cnetplot() to visualize GO enrichment results, I encountered a reproducible issue:

  • If I simply take the top 15 terms by p.adjust (Method 1), cnetplot(color_edge="category") works fine.
  • If I subset terms using grepl("signal|pathway") and then take the top 15 (Method 2), cnetplot(color_edge="category") fails with:
Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto),  :
  Viewport has zero dimension(s)

This suggests that whenever the enrichResult object is subset using grepl, cnetplot(color_edge="category") cannot render properly.


Reproducible Code

library(clusterProfiler)
library(enrichplot)
library(DOSE)

# Built-in dataset
data(geneList, package = "DOSE")
de <- names(geneList)[1:100]

yy <- enrichGO(de, 'org.Hs.eg.db', ont="BP", pvalueCutoff=0.01)
yy <- setReadable(yy, 'org.Hs.eg.db', 'ENTREZID')

# Method 1: global top15
yy1 <- yy
yy1@result <- head(yy@result[order(yy@result$p.adjust), ], 15)

# Method 2: grepl subset + top15
df_sel <- yy@result[
  yy@result$p.adjust < 0.05 &
    grepl("signal|pathway", yy@result$Description, ignore.case=TRUE),
]
df_sel <- head(df_sel[order(df_sel$p.adjust), ], 15)

yy2 <- yy
yy2@result <- df_sel

# Test plots
p1 <- try(cnetplot(yy1, showCategory=15, color_edge="category"))  # works
p2 <- try(cnetplot(yy2, showCategory=15, color_edge="category"))  # error
p3 <- try(cnetplot(yy2, showCategory=15))                         # works

print(p1)  # OK
print(p2)  # Error: Viewport has zero dimension(s)
print(p3)  # OK

Expected Behavior

cnetplot() should be able to handle enrichResult objects subset by grepl and render edges with color_edge="category" without error.


Actual Behavior

  • Works fine with global topN terms.
  • Fails with grepl subset when color_edge="category" is specified.
  • Works if color_edge is not specified.

Environment

R version 4.5.2 (2025-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22000)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] enrichplot_1.30.0      clusterProfiler_4.18.0 readxl_1.4.5           ggplot2_4.0.1          org.Mm.eg.db_3.22.0    openxlsx_4.2.8.1      
 [7] KEGGREST_1.50.0        GO.db_3.22.0           AnnotationDbi_1.72.0   IRanges_2.44.0         S4Vectors_0.48.0       Biobase_2.70.0        
[13] BiocGenerics_0.56.0    generics_0.1.4         dplyr_1.1.4            GOSemSim_2.36.0        DOSE_4.4.0  

Question

Is this a bug in how cnetplot() handles subsetted enrichResult objects?


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions