diff --git a/PowerBI/pbi_viz.pbix b/PowerBI/pbi_viz.pbix new file mode 100644 index 00000000..1a46f9ce Binary files /dev/null and b/PowerBI/pbi_viz.pbix differ diff --git a/README.md b/README.md index 7ee8e8fb..b063c789 100644 --- a/README.md +++ b/README.md @@ -1,142 +1,51 @@ # 02-DataVis-5ways -Assignment 2 - Data Visualization, 5 Ways +Nicholas Alescio - Assignment 2 - Data Visualization, 5 Ways === -Now that you have successfully made a "visualization" of shapes and lines using d3, your next assignment is to successfully make a *actual visualization*... 5 times. +In this project, five visualizations were created for one dataset. Three languages (JavaScript, Python, R) and two visualization tools (Flourish, PowerBI) were used in this project. -The goal of this project is to gain experience with as many data visualization libraries, languages, and tools as possible. +# R + ggplot2 -I have provided a small dataset about cars, `cars-sample.csv`. -Each row contains a car and several variables about it, including miles-per-gallon, manufacturer, and more. - -Your goal is to use 5 different tools to make the following chart: - -![ggplot2](img/ggplot2.png) - -These features should be preserved as much as possible in your replication: - -- Data positioning: it should be a downward-trending scatterplot as shown. Weight should be on the x-axis and MPG on the y-axis. -- Scales: Note the scales do not start at 0. -- Axis ticks and labels: both axes are labeled and there are tick marks at 10, 20, 30, etcetera. -- Color mapping to Manufacturer. -- Size mapping to Weight. -- Opacity of circles set to 0.5 or 50%. - -Other features are not required. This includes: - -- The background grid. -- The legends. - -Note that some software packages will make it **impossible** to perfectly preserve the above requirements. -Be sure to note where these deviate. - -Improvements are also welcome as part of Technical and Design achievements. - -Libraries, Tools, Languages ---- - -You are required to use 5 different tools or libraries. -Of the 5 tools, you must use at least 3 libraries (libraries require code of some kind). -This could be `Python, R, Javascript`, or `Java, Javascript, Matlab` or any other combination. -Dedicated tools (i.e. Excel) do not count towards the language requirement. - -Otherwise, you should seek tools and libraries to fill out your 5. - -Below are a few ideas. Do not limit yourself to this list! -Some may be difficult choices, like Matlab or SPSS, which require large installations, licenses, and occasionally difficult UIs. - -I have marked a few that are strongly suggested. - -- R + ggplot2 `<- definitely worth trying` -- Excel -- d3 `<- since the rest of the class uses this, we're requiring it` -- Matplotlib -- three.js `<- well, it's a 3d library. not really recommended, but could be "interesting"` -- p5js `<- good for playing around. not really a chart lib` -- Tableau -- Java 2d -- GNUplot -- Vega-lite <- `<- recently much better. look for the high level js implementations` -- Flourish <- `<- popular last year` -- PowerBI -- SPSS - -You may write everything from scratch, or start with demo programs from books or the web. -If you do start with code that you found, please identify the source of the code in your README and, most importantly, make non-trivial changes to the code to make it your own so you really learn what you're doing. - -Tips ---- - -- If you're using d3, key to this assignment is knowing how to load data. -You will likely use the [`d3.json` or `d3.csv` functions](https://github.com/mbostock/d3/wiki/Requests) to load the data you found. -Beware that these functions are *asynchronous*, meaning it's possible to "build" an empty visualization before the data actually loads. - -- *For web languages like d3* Don't forget to run a local webserver when you're debugging. -See this [ebook](http://chimera.labs.oreilly.com/books/1230000000345/ch04.html#_setting_up_a_web_server) if you're stuck. - - -Readme Requirements ---- - -A good readme with screenshots and structured documentation is required for this project. -It should be possible to scroll through your readme to get an overview of all the tools and visualizations you produced. - -- Each visualization should start with a top-level heading (e.g. `# d3`) -- Each visualization should include a screenshot. Put these in an `img` folder and link through the readme (markdown command: `![caption](img/)`. -- Write a paragraph for each visualization tool you use. What was easy? Difficult? Where could you see the tool being useful in the future? Did you have to use any hacks or data manipulation to get the right chart? +R is a language primarily focused on statistical computing. +ggplot2 is a popular library for charting in R. -Other Requirements ---- +To visualized the cars dataset, I made use of ggplot2's `geom_point()` layer, with aesthetics functions for the color and size. -0. Your code should be forked from the GitHub repo. -1. Place all code, Excel sheets, etcetera in a named folder. For example, `r-ggplot, matlab, mathematica, excel` and so on. -2. Your writeup (readme.md in the repo) should also contain the following: +Since I had never used R before, it took me a decent amount of time just to figure out how to run a script... eventually I found good documentation and everything worked out! -- Description of the Technical achievements you attempted with this visualization. - - Some ideas include interaction, such as mousing over to see more detail about the point selected. -- Description of the Design achievements you attempted with this visualization. - - Some ideas include consistent color choice, font choice, element size (e.g. the size of the circles). +![ggplot2](img/ggplot2.png) -GitHub Details ---- +# d3.js -- Fork the GitHub Repository. You now have a copy associated with your username. -- Make changes to fulfill the project requirements. -- To submit, make a [Pull Request](https://help.github.com/articles/using-pull-requests/) on the original repository. +D3 is a JavaScript library for visualizing data with HTML, SVG, and CSS. -Grading ---- +The challenge here was finding a way to make everything actually appear in the location I wanted things to be (my circles kept rendering off the screen). Margins helped me tremendously with solving that issue. I also included some code to hide n/a values. D3, being a JavaScript library, only serves to make JavaScript more powerful and more flexible for any and all vizualization tasks. -Grades on a 120 point scale. -24 points will be based on your Technical and Design achievements, as explained in your readme. +![JavaScript D3](img/javascript-d3.png) -Make sure you include the files necessary to reproduce your plots. -You should structure these in folders if helpful. -We will choose some at random to run and test. +# Python + Seaborn -**NOTE: THE BELOW IS A SAMPLE ENTRY TO GET YOU STARTED ON YOUR README. YOU MAY DELETE THE ABOVE.** +Python is an interpreted language that can be used for pretty much any high-level task, popular due to its vast amounts of libraries. For this viz, the Seaborn library (based on matplotlib) was used. This viz was the most straightforward and caused me the least issues. The only complication I ran into was having to use the pandas library to import the csv, since it was being pulled locally and not over the internet. Because of Python's flexibility and general-purpose nature, I see it being useful for any simple vizualization task. -# R + ggplot2 + R Markdown +![Seaborn](img/python-seaborn.png) -R is a language primarily focused on statistical computing. -ggplot2 is a popular library for charting in R. -R Markdown is a document format that compiles to HTML or PDF and allows you to include the output of R code directly in the document. +# PowerBI -To visualized the cars dataset, I made use of ggplot2's `geom_point()` layer, with aesthetics functions for the color and size. +PowerBI is a Microsoft tool used for creating vizualizations in the field of business intelligence. Expecting this to be the easiest of the five, PowerBI ended up providing the most issues for me. Issue number one was needing to clean the data in order to display MPG on the y-axis (and also changing the data type of the MPG column, which defaulted to "Text" because of N/A values. Issue number two was trying to figure out how to scale points based on Weight, which didn't end up working out too great because PowerBI doesn't like using individual data points for sizes in their "Scatter" viz. -While it takes time to find the correct documentation, these functions made the effort creating this chart minimal. +![PowerBI](img/powerbi.png) -![ggplot2](img/ggplot2.png) +# Flourish -# d3... +Flourish is a free, online data viz platform that allows users to quickly create interactive visualizations. This viz took me the least amount of time, and I found it to be very user-friendly (having no experience, it took me ~5 minutes to create the viz I was looking for). -(And so on...) +![Flourish](img/flourish.png) ## Technical Achievements -- **Proved P=NP**: Using a combination of... -- **Solved AI Forever**: ... +- **Automatic hiding of n/a values in d3** +- **Filtering out n/a values in PowerBI and reinterpreting datatype for MPG column** ### Design Achievements -- **Re-vamped Apple's Design Philosophy**: As demonstrated in my colorscheme... +- **Actually re-vamped Apple's Design Philosophy**: Haha just kidding, I'm not smart enough for that diff --git a/ggplot2/ggplot2.R b/ggplot2/ggplot2.R new file mode 100644 index 00000000..944354c5 --- /dev/null +++ b/ggplot2/ggplot2.R @@ -0,0 +1,10 @@ +library(ggplot2) + +# Run in the directory of this script + +cars <- read.csv(file="../cars-sample.csv",head=TRUE,sep=",") + +p <- ggplot(data=cars, mapping=aes(x=Weight, y=MPG, color=Manufacturer)) + + geom_point(aes(size=Weight), alpha=0.5) + +print(p) \ No newline at end of file diff --git a/img/flourish.png b/img/flourish.png new file mode 100644 index 00000000..9f1d5670 Binary files /dev/null and b/img/flourish.png differ diff --git a/img/ggplot2.png b/img/ggplot2.png index aa107c66..306603f5 100644 Binary files a/img/ggplot2.png and b/img/ggplot2.png differ diff --git a/img/javascript-d3.png b/img/javascript-d3.png new file mode 100644 index 00000000..bdcb8856 Binary files /dev/null and b/img/javascript-d3.png differ diff --git a/img/powerbi.png b/img/powerbi.png new file mode 100644 index 00000000..1231b0b6 Binary files /dev/null and b/img/powerbi.png differ diff --git a/img/python-seaborn.png b/img/python-seaborn.png new file mode 100644 index 00000000..ec28f48e Binary files /dev/null and b/img/python-seaborn.png differ diff --git a/javascript-d3/cars.html b/javascript-d3/cars.html new file mode 100644 index 00000000..062d6add --- /dev/null +++ b/javascript-d3/cars.html @@ -0,0 +1,85 @@ + + + + + + Cars-sample + + + + + +
+ +
+ + \ No newline at end of file diff --git a/python-seaborn/main.py b/python-seaborn/main.py new file mode 100644 index 00000000..da2ea067 --- /dev/null +++ b/python-seaborn/main.py @@ -0,0 +1,13 @@ +import seaborn as sns +import pandas as pd +import matplotlib.pyplot as plt +import os.path + +def main(): + print("hello!") + cars = pd.read_csv(os.path.dirname(__file__) + '/../cars-sample.csv') + sns.relplot(x="Weight", y="MPG", data=cars, hue="Manufacturer", size="Weight", alpha=0.5) + plt.show() + +if __name__ == "__main__": + main()