cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
49 stars 20 forks source link

Not able to customize node height and weight for ellipse #38

Closed Krithika-Bhuvan closed 5 years ago

Krithika-Bhuvan commented 5 years ago

Hello, I'm trying to customize the cytoscape visualization, and am having some trouble.

I used the provided vignettes to come up with this code. When i view this network in cytoscape , the nodes are "circles", not "ellipses" like i want. The node height and weight seem to be fixed (locked). What am I missing ?

Ideally I want the ellipse node to be such that it will correctly fit the label inside it - is there anyway to do this ?

Thanks, K


nodes <- data.frame(id=c("node 0","node 1","node 2","node 3"),
           group=c("A","A","B","B"), # categorical strings
           score=as.integer(c(20,10,15,5)), # integers
           stringsAsFactors=FALSE)
edges <- data.frame(source=c("node 0","node 0","node 0","node 2"),
           target=c("node 1","node 2","node 3","node 3"),
           interaction=c("inhibits","interacts","activates","interacts"),  # optional
           weight=c(5.1,3.0,5.2,9.9), # numeric
           stringsAsFactors=FALSE)

createNetworkFromDataFrames(nodes,edges, title="my first network", collection="DataFrame Example")
# Check cytoscape window to see if you can see the network

#  Creating a new style
style.name = "myStyle1"
defaults <- list(NODE_SHAPE="ellipse",
                 NODE_WIDTH=85,
                 NODE_HEIGHT=55,
                 EDGE_TRANSPARENCY=255,
                 NODE_LABEL_POSITION="c,c,c,0.00,0.00",
                 NODE_LABEL_FONT_SIZE = 15,
                 labelFontWeight = "bold")
nodeLabels <- mapVisualProperty('node label','id','p')
nodeFills <- mapVisualProperty('node fill color','group','d',c("A","B"), c("#FF9900","#66AAAA"))
arrowShapes <- mapVisualProperty('Edge Target Arrow Shape','interaction','d',c("activates","inhibits","interacts"),c("Arrow","T","None"))
edgeWidth <- mapVisualProperty('edge width','weight','p')

createVisualStyle(style.name, defaults, list(nodeLabels,nodeFills,arrowShapes,edgeWidth))
setVisualStyle(style.name)```
AlexanderPico commented 5 years ago

Good question! Cytoscape has a nifty (and tricky) toggle for locking node height and width to the same "size" value. In order to set them independently, you have to make sure the lock is off. Here's the command to do that:

lockNodeDimensions(FALSE, style.name)
Krithika-Bhuvan commented 5 years ago

Excellent ! Got it working. Thanks !

AlexanderPico commented 5 years ago

Great. Updated vignette for others in the future: https://github.com/cytoscape/RCy3/blob/RELEASE_3_8/vignettes/Overview-of-RCy3.Rmd#L89

Thanks again for pointing out this missing detail.