{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", "
\n", " Run in Google Colab\n", " \n", " View on Github\n", " \n", " View raw on Github\n", "
" ] }, { "cell_type": "markdown", "metadata": { "id": "8Es4WyC82rAB" }, "source": [ "# Module 14: Networks\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Gephi and Cytospace\n", "\n", "We will introduce two network visualization tools. The first one is Gephi. It can perform a variety of network analysis and can produce pretty visualizations quickly. The downside is that it's currently not well maintained and as a result the installation has become problematic, particularly in the recent systems including Windows 10 and MacOS 10.12+. \n", "\n", "You can download and install Gephi: [https://gephi.org/](https://gephi.org/). \n", "\n", "Depending upon what version of Gephi you use the location of some buttons and tabs may vary, but the general functionality is roughly the same. If you want to know more about Gephi or what file formats it can read/write you can visit their documentation page. You can also check out some other tutorials online.\n", "\n", "Another tool is the Cytoscape. It's developed by biologists & bioinformaticians and thus geared towards biological networks. Additionally, it does not have many network analysis functionalities. However, it is more stable and sensible in many ways than Gephi. You can download it at [http://www.cytoscape.org/](http://www.cytoscape.org/) and check out the tutorials at: [https://github.com/cytoscape/cytoscape-tutorials/wiki](https://github.com/cytoscape/cytoscape-tutorials/wiki).\n", "\n", "For this assignment, you can choose one from these two, and experiment with a small network. We'll use the Les Miserables graph, which can be downloaded from: [http://www-personal.umich.edu/~mejn/netdata/](http://www-personal.umich.edu/~mejn/netdata/). (Feel free to play with other networks too: [https://github.com/gephi/gephi/wiki/Datasets](https://github.com/gephi/gephi/wiki/Datasets)) \n", "\n", "Once you have the Les Miserables graph,\n", "\n", "For Gephi users:\n", "* Load the network into Gephi as an undirected graph\n", "* Use a force-directed layout to obtain a good layout (also play with other layouts)\n", "* Find communities (modules) and color nodes based on the communities\n", "* Tweak various visual encodings to obtain a good visualization. For example - node size, node labels, edge weights etc\n", "* Export to a PDF or a PNG file\n", "* and upload the image file. \n", "\n", "For Cytospace users:\n", "* Load the network into Cytospace\n", "* Apply the edge-weighted spring embedded layout (also play with other layouts such as \"organic\")\n", "* Color the nodes and tweak various visual encodings to obtain a good visualization\n", "* Export to a PDF or a PNG file\n", "* and upload the image file. \n", "\n", "\n", "\n", "----\n", "\n", "### How to install Gephi on Microsoft Windows with Oracle Java 9 (by Xuan Wang)\n", "\n", "Gephi can't find java by default on Windows with JDK 9. \n", "I don't know whether others have encountered the same problem. So I am writing it down. Hope it is helpful for somebody.\n", "\n", "**First**, you need to download and install Oracle Java. We'll use Java 9. (We don't have support for Java 10.)\n", "http://www.oracle.com/technetwork/java/javase/downloads/index.html\n", "Note: You can install JRE or JDK. JRE needs 110MB space and JDK needs 610MB space.\n", "\n", "**Second**, follow the link on homework page to download and install Gephi.\n", "\n", "**Third**: Configure Gephi. Gephi by default can't find your JRE 9. \n", "You need to edit `C:\\Program Files\\Gephi-0.9.2\\etc\\gephi.conf`, add this line\n", "`jdkhome=\"C:\\Program Files\\Java\\jre-9.0.4`\n", "Change the path to your java installation path. You are good to go.\n", "\n", "Java 9 by default will add `C:\\ProgramData\\Oracle\\Java\\javapath\\` to `PATH` and write Windows Registry for JRE. CLASS_PATH is obsoleted in Java 9 and JAVA_HOME is not neccesary for most applications since it is reserved for private JRE. Anyway, Gephi simply doesn't buy it. It doesn't recognize JRE 9's javapath folder. \n", "\n", "You may try to set JAVA_HOME, it might work too.\n", "\n", "Well, Oracle has changed the directory structure for JRE on Windows. That is why they use javapath instead. If you are using `conf` files or `JRE_HOME/JAVA_HOME`, whenever you upgrade your JRE, the path will change and you have to set it all over again. If Gephi could use the new javapath, upgrdaing java would have no impact on setting.\n", "\n", "\n", "# Interactive visualizations\n", "\n", "## Controlling plot elements\n", "\n", "Let's start with this example on Vega editor: [https://vega.github.io/editor/#/examples/vega/scatter-plot-null-values](https://vega.github.io/editor/#/examples/vega/scatter-plot-null-values).\n", "\n", "Notice that the drop-down list allows us to choose what to plot in the `x` and `y` fields: IMDB rating, Rottentomatoes rating, worldwide gross, and so on. How to achieve this?\n", "\n", "## `Signals` in Vega\n", "\n", "From the Vega documentation:\n", "\n", "> \"Signals are dynamic variables that parameterize a visualization and can drive interactive behaviors.\" \n", "\n", "Let's look at the code:\n", "\n", "``` \n", "\"signals\": [\n", " { \"name\": \"xField\", \n", " \"value\": \"IMDB_Rating\",\n", " \"bind\": {\n", " \"input\": \"select\", \n", " \"options\": [\n", " \"IMDB_Rating\", \"Rotten_Tomatoes_Rating\", \n", " \"US_Gross\", \"Worldwide_Gross\"\n", " ]\n", " }\n", " },\n", " ...]\n", "```\n", "\n", "`name` is the name of this signal. In this case, `yField` as can be seen in the plot.\n", "\n", "`bind` creates the input, in this case, the drop-down list. It can also be a checkbox, a radio button, etc.\n", "\n", "Then, we want to use the input to `signal` to update the plot. In this plot, the element to be updated is the `marks`.\n", "\n", "```\n", "\"marks\": [\n", " {\n", " \"type\": \"symbol\",\n", " \"from\": {\"data\": \"valid\"},\n", " \"encode\": {\n", " \"enter\": {\n", " \"size\": {\"value\": 50},\n", " \"tooltip\": {\"field\": \"tooltip\"}\n", " },\n", " \"update\": {\n", " \"x\": {\"scale\": \"xscale\", \"field\": {\"signal\": \"xField\"}},\n", " \"y\": {\"scale\": \"yscale\", \"field\": {\"signal\": \"yField\"}},\n", " \"fill\": {\"value\": \"steelblue\"},\n", " \"fillOpacity\": {\"value\": 0.5},\n", " \"zindex\": {\"value\": 0}\n", " },\n", " \"hover\": {\n", " \"fill\": {\"value\": \"firebrick\"},\n", " \"fillOpacity\": {\"value\": 1},\n", " \"zindex\": {\"value\": 1}\n", " }\n", " }\n", " },\n", " ...\n", " ]\n", "```\n", " \n", "In the `update` key, we want to change the `field` of x and y. Previously, we would specify a field as:\n", " \n", "```\n", "\"x\": {\"scale\": \"xscale\", \"field\": \"IMDB_Rating\"}\n", "```\n", "However, here we use the input from the `xField` signal:\n", "\n", "```\n", "\"x\": {\"scale\": \"xscale\", \"field\": {\"signal\": \"xField\"}}\n", "```\n", "\n", "That's it!\n", "\n", "\n", "Assignment: add radio buttons to allow changing the color of the points. Your result should look like this:\n", "\n", "![example](https://github.com/yy/dviz-course/raw/master/docs/m14-networks/m14_example.png)\n", "\n", "**Submit the URL of your work (can be obtained using the webpage's \"share\" feature).**\n", " \n", " \n", " \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12" } }, "nbformat": 4, "nbformat_minor": 0 }