tidymodels / corrr

Explore correlations in R
https://corrr.tidymodels.org
Other
589 stars 56 forks source link

How to custom color nodes in network_plot()? #48

Closed vertesy closed 6 years ago

vertesy commented 6 years ago

I have a data set, where the data comes in different categories. These categories I would like to indicate as the color of the nodes. The categories I store in a numeric vector AnnotVector.

I tried:

corrr::correlate(DATA, method = "pearson" %>% network_plot()
# Works WO colors. 

# Then
# COLOR = AnnotVector # Use once works
COLOR = 'darkblue'
corrr::correlate(DATA, method = "pearson" %>% network_plot() + geom_point(color=COLOR)
# no coloring
drsimonj commented 6 years ago

This is not easy to achieve with corrr, nor is it something I would implement now (want to move away from adding customisable features to quick plots and more towards better integration with general plotting tools).

For now, I'd recommend taking a different approach such as building the plot from scratch with ggraph. Here's a post I've written to get you started: https://drsimonj.svbtle.com/how-to-create-correlation-network-plots-with-corrr-and-ggraph

vertesy commented 6 years ago

Extracting coordinates

Sorry for hammering on this issue, but is it possible then to extract the coordinates of the points for custom plotting?

I looked at the object produced by obj = network_plot(mydat) but it seems quite complex. I guess I should find somewhere dataframe with X and Y coordinates for each node.

Could you help me if it is stored in obj, and how can I extract it? Thanks!

vertesy commented 6 years ago

Ok, this was one of longest way I ever took to get the XY coordinates from a 2D plot ...

XX = corrr::correlate(DAT)
plot.obj=network_plot(XX)
plot.obj.bld = ggplot_build(plot.obj)
XY.coord = plot.obj.bld$data[[3]][,1:2]
plot(XY.coord)

Finally this issue can be really closed.

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.