如何在EnhancedVolcano中调用ggrepel的nudge_x参数?
在EnhancedVolcano中设置ggrepel的nudge_x参数加长连接线
我希望优化EnhancedVolcano生成的火山图,手动调整并加长连接线。已知该包可通过内部解析ggrepel的参数实现自定义,想在现有代码中设置nudge_x = 2,但不清楚具体用法。
现有代码如下:
EnhancedVolcano(reordered_b1, lab = rownames(reordered_b1), FCcutoff = 0.5, pCutoff = 0.05, selectLab = c('Gene1', 'Gene2', 'Gene3', 'Gene4'), labSize = 4, labCol = 'black', labFace = 'bold', boxedLabels = F, drawConnectors = T, widthConnectors = 1, lengthConnectors = unit(0, 'npc'), shapeCustom = keyvals.shape, colCustom = keyvals.color, colAlpha = .75, pointSize = 5, title = vpTitle, titleLabSize = 10, subtitle = NULL, legendPosition = 'none', caption = NULL, ylab = bquote(~-Log[10]~FDR), xlab = bquote(~Log[2]~Fold~Change), axisLabSize = 10, xlim = c(-6,6), gridlines.major = FALSE, gridlines.minor = FALSE, border = 'full')
解决方案
EnhancedVolcano函数支持通过**省略号(...)**传递ggrepel包的参数,因此直接在函数调用中添加nudge_x = 2即可实现加长连接线的需求。
修改后的代码如下:
EnhancedVolcano(reordered_b1, lab = rownames(reordered_b1), FCcutoff = 0.5, pCutoff = 0.05, selectLab = c('Gene1', 'Gene2', 'Gene3', 'Gene4'), labSize = 4, labCol = 'black', labFace = 'bold', boxedLabels = F, drawConnectors = T, widthConnectors = 1, lengthConnectors = unit(0, 'npc'), # 添加ggrepel的nudge_x参数实现连接线加长 nudge_x = 2, shapeCustom = keyvals.shape, colCustom = keyvals.color, colAlpha = .75, pointSize = 5, title = vpTitle, titleLabSize = 10, subtitle = NULL, legendPosition = 'none', caption = NULL, ylab = bquote(~-Log[10]~FDR), xlab = bquote(~Log[2]~Fold~Change), axisLabSize = 10, xlim = c(-6,6), gridlines.major = FALSE, gridlines.minor = FALSE, border = 'full')
补充说明
nudge_x参数会被EnhancedVolcano内部传递给ggrepel的标签绘制函数,通过横向偏移标签位置间接加长连接线长度。- 如果需要针对上调/下调基因设置不同方向的偏移,可使用向量形式的
nudge_x,比如nudge_x = ifelse(reordered_b1$log2FC > 0, 2, -2),让上调基因标签右移、下调基因标签左移,保证连接线均向外延伸。
内容的提问来源于stack exchange,提问作者CeC
相关产品推荐
相关产品推荐

