Hello! This week I also went over the last couple chapters in "Data Visualization with R" by Rob Kabacoff. We skipped chapters 10 and 11 since we went over most of the pertinent information they contained in previous chapters, and went straight to chapters 12 and 13.

Chapter 12 is a fun chapter about interactive graphs. I had to download some additional packages to make them work, such as leaflet.

Chapter 13 provides advice on how to make the graphs most appealing. It goes over labeling, picking colors, and how to best customize your graphs so they are easy and appealing to look at.

Chapter 12: Interactive Graphs

R does not produce these graphs on its own, and makes a connection with JavaScript to make these graphs. Unlike the other graphs in this book that look just as nice on paper as on a screen, interactive graphs need to be viewed on an app or web page.

Leaflet

Leaflet is a JavaScript library for interactive maps. The leaflet package in R is used to create interactive graphs. The book doesn't provide the code used to install leaflet, so I searched "create leaflet graph on r" on Googe. Et voila! The first link gave me the code: install.packages("leaflet"). You can make dot density and choropleth graphs using leaflet. Apparently the package website has  detailed tutorial for using leaflet. I clicked on a github link, so I'm not sure if it's the official webpage or not, but I think it is: https://rstudio.github.io/leaflet/


Plotly

Plotly is a commercial and open source product for creating interactive graphs. This package allows you to make plotly graphs in R, and every ggplot2 graph can be made into a plotly graph. This interactive graph type does not require you to download any additional packages outside of what the book provides, so that was nice! You can't see it in the picture, but when I hover my mouse over the points, a label pops up that tells me that points hightway mileage, vehicle class, and engine displacement:


rBokeh

rBokeh is the interface for the Bokeh graph library. This one needed a package downloaded. I decided to make an educated guess and see if install.packages("rbokeh") would download it. It worked! Much like the previous graph, hovering over each element provided information on that element (or elements, if there was multiple at that point).


rCharts

rCharts can create several different types of interactive graphs. The example in the book is an interactive bar graph that allows you to hover over the bars and choose between grouped vs. stacked plots, as well as include or exclude variables. I was not able to view this graph. I tried seeing if I could simply download the package the same way I did the other 2, but it didn't work, and gave me and error about it not working on my version.

Highcharter

The highcharter package also requires a connection to the JavaScript library. I downloaded this package the same way as I did the other packages.


Chapter 13: Advice/Best Practices

This chapter gives a more in depth summary for making your graphs be as readable and good looking as possible.

Labeling

When you are making graphs, everything should be labeled. A quick checklist of things that need labeling on a graph is as follows:

  • title
  • subtitle
  • caption
  • axis labels
  • legend
  • lines and bars
Signal to Noise Ratio

This section is basically about eliminating unnecessary "noise" on a graph that might take away from the main point of the graph. This can include long titles or labels, too many labels, too many colors, a distracting background, or other unnecessary customizations. Although not very pretty, the best graph is one that is plain and uncluttered.

Color Choice

When picking colors for a graph, you want the colors to show differences, similarities, and be relevant to your graph. You also want to make sure that your labels are still legible. Take the heatmap, for example. It used a palette of colors that all looked good together, but still had enough contrast to show differences and similarities in categories. The RColorBrewer package provides many color palettes you can use.

y-Axis Scaling

This is used to show how insignificant, or big an effect is on your graph. You want to make sure your scaling is accurate to the information you are trying to present, especially if you are trying to show the difference between to variables. If your y-axis scaling is not done right, it might look like your variables are too similar, or too different. Take these examples from the book. In the first picture, it shows a clear difference in mean salary between men and women. In the second picture, wherethe y-axis has a larger range, it looks like there is almost no difference:

In addition to the above suggestions, your graphs should also contain and attribution, which notes the source of the data being displayed.
This chapter also lists additional sources to learn about using ggplot2 and R in depth.

That's it for this semester! I had a lot of fun learning a new coding language. It was nice combining some computer science knowledge with biology, and I think what I learned will come in handy for future projects and finding a career!

Comments

Popular posts from this blog

Week 13

Blog Post 2 -- Spring 2023 -- Professional Identity

Semester 2 week 4