我希望沿着线的长度制作一个带有箭头(或类似的 V 形)的有向网络图...
igraph
库似乎使用基本的 polygon
函数,它接受 lty
来指定线类型,但这些仅限于各种破折号。
有没有办法制作自定义符号(甚至使用pch
中的三角形)在R中形成一条线?
制作图表的最少代码:
require(igraph)
gr = graph_from_literal( A -+ B -+ C )
plot(gr,edge.curved=TRUE)
顺便说一句,如果另一个网络分析库支持这一点,我会很好地使用它。我询问了 ggraph
的开发者,他说无法做到这一点。
最佳答案
Cytoscape
和 RCy3
库用于创建网络图。
安装 cytoscape 版本 3 及更高版本 from here 。然后启动 cytoscape GUI(图形用户界面) session 。
此答案中使用的版本为cytoscape: 3.4.0
和RCy3: 1.5。 2
操作系统:Windows-7
# load libraries
library('RCy3')
# create cytoscape connection
cy <- RCy3::CytoscapeConnection()
RCy3::deleteAllWindows(cy) # delete all windows in cytoscape
hideAllPanels(cy) # hide all panels
# create node and edge data and create graphNEL object
node.tbl <- data.frame(Node.Name = c('A', 'B', 'C'))
edge.tbl <- data.frame(Gene.1 = c('A', 'B'),
Gene.2 = c('B', 'C'))
g <- cyPlot(node.tbl, edge.tbl)
g
# A graphNEL graph with directed edges
# Number of Nodes = 3
# Number of Edges = 2
# create cytoscape window and display the graph
window_title <- 'example'
cw <- RCy3::CytoscapeWindow(window_title, graph=g, overwrite=FALSE)
RCy3::displayGraph(cw)
# set visual style and layout algorithm
vis_style <- 'Curved' # getVisualStyleNames(cw)[7]
RCy3::setVisualStyle(cw, vis_style)
RCy3::layoutNetwork(obj = cw, layout.name = "circular")
RCy3::layoutNetwork(obj = cw, layout.name = "kamada-kawai")
# get all edges
getAllEdges(cw)
# [1] "A (unspecified) B" "B (unspecified) C"
# get cytoscape supported line types
supported_styles <- getLineStyles (cw)
supported_styles
# [1] "EQUAL_DASH" "PARALLEL_LINES" "MARQUEE_DASH" "MARQUEE_EQUAL" "SOLID" "FORWARD_SLASH" "DASH_DOT" "MARQUEE_DASH_DOT"
# [9] "SEPARATE_ARROW" "VERTICAL_SLASH" "DOT" "BACKWARD_SLASH" "SINEWAVE" "ZIGZAG" "LONG_DASH" "CONTIGUOUS_ARROW"
# set edge line type
setEdgeLineStyleDirect(cw, "A (unspecified) B", supported_styles [16]) # "CONTIGUOUS_ARROW"
setEdgeLineStyleDirect(cw, "A (unspecified) B", supported_styles [9]) # "SEPARATE_ARROW"
# save network as image in the current working directory
fitContent (cw)
setZoom(cw, getZoom(cw) - 1) # adjust the value from 1 to a desired number to prevent cropping of network diagram
saveImage(obj = cw,
file.name = 'example',
image.type = 'png',
h = 700)
有关详细信息,请阅读?RCy3::setEdgeLineStyleDirect
。
另外,对于 cytoscape 边缘属性,请参阅 here
安装 RCy3:
# Install RCy3 - Interface between R and Cytoscape (through cyRest app)
library('devtools')
remove.packages("BiocInstaller")
source("https://bioconductor.org/biocLite.R")
biocLite("BiocGenerics")
biocLite("bitops")
install_github("tmuetze/Bioconductor_RCy3_the_new_RCytoscape")
关于r - R 中网络图的自定义线条样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41751819/