grp_matrix = matrix(c(1, 0,
0, 1), nrow = 2, ncol = 2)
n_grp <- nrow(grp_matrix)
use_color <- rainbow_hcl(ncol(grp_matrix), c = 100)
n_color <- length(use_color)
use_color = color
# defines how many pie segments are needed, common to all the pie-charts
pie_area <- rep(1 / n_color, n_color)
names(pie_area) <- rep("", n_color)
desat_color <- desaturate(use_color)
names(desat_color) <- names(use_color)
piechart_strings <- purrr::map_dfr(rownames(grp_matrix), function(i_grp){
tmp_logical <- grp_matrix[i_grp, ]
tmp_color <- use_color
# add the proper desaturated versions of the colors
tmp_color[!tmp_logical] <- desat_color[!tmp_logical]
out_str = paste0('piechart: attributelist="',
paste(colnames(grp_matrix), collapse = ','),
'" ',
'colorlist="',
paste(tmp_color, collapse = ','),
'" ',
'arcstart=-90 showlabels=false')
data.frame(colorlist = out_str)
})
tmp_matrix = as.data.frame(matrix(1, nrow = nrow(piechart_strings),
ncol = ncol(grp_matrix)))
names(tmp_matrix) = colnames(grp_matrix)
piechart_df = cbind(tmp_matrix, piechart_strings)
# after merging this with the node information to
# put the right things with the right node
# this gives **node_vis_df** below
RCy3::setNodeShapeDefault("ELLIPSE")
RCy3::setNodeSizeDefault(35)
RCy3::loadTableData(node_vis_df, data.key.column = "name", table = "node", table.key.column = "name")
RCy3::updateStyleMapping("default",
RCy3::mapVisualProperty("NODE_CUSTOMGRAPHICS_1", "colorlist", "p"))I have a package, {categoryCompare2} (Flight 2022) that I’ve been working on for a while, and recently wanted to make available on our labs r-universe (“The ’Moseleybioinformaticslab’ Universe,” n.d.).
For some of the current visualization, we use Cytoscape to examine annotation similarity graphs, coupling the R together with Cytoscape via {RCy3} (Gustavsen et al. 2019). In the previous iteration, we had used actual piechart images generated by R, and then used setNodeImageDirect to point the node images to local image files.
However, the latest iteration of {RCy3} has essentially lost that functionality. However, there is a new visualization plugin that can do similar things, enhancedGraphics (Morris JH 2014).
Alexander Pico, one of the primary {RCy3} developers, provided me with the guidance for a code solution (Pico 2022), which I’ve adapted below.
References
Reuse
Citation
@online{mflight2022,
author = {Robert M Flight},
title = {Pie {Charts} in {RCy3}},
date = {2022-01-06},
url = {https://rmflight.github.io/posts/2022-01-06-pie-charts-in-rcy3},
langid = {en}
}