3. Visualization and Animation in R
Animated graphs can adds a unique element to data visualization which may
provide greater detail than a static graph.
Improves the aesthetics of a presentation or report which will help retain a
viewer’s attention.
Why we need visualization and animation for data analysis ?
How to create Visualization and Animation in R ?
Packages Available: GoogleVis, GGplot2, ImageMagick, ChoroplethrMaps,
Animation, SWFtools, GGvis, rgl, htmlwidgets, rCharts etc.
4. Packages Used---1
1) Shiny: Create interactive web applications using R code
Dashboard app: All code files must be placed in the same directory:
UI.R: defines how the web application looks to users.
Server.R: R code input where you perform your data analysis.
Global.R: Important when the variables are shared between the UI.R and Server.R
All R code in a Shiny app is run in the global environment.
2) GoogleVis : Interface between R and the Google Charts
Allow users to visualize data without uploading the data to Google
GvisBubbleChart: Create Bubble plots
GvisMotionChart: Create animation plots--- rendered by the web browser in Flash
GvisMap: Create interactive map
5. Packages Used---2
3) Magick : Advanced Image-Processing in R
Most comprehensive open-source image processing library available
Supports many common formats: png, jpeg, tiff, pdf, gif, etc
Imagemagick tool is required to run this package
4) Choroplethr : Used for making heat maps
5) Dplyr : Power tool for Data Manipulation----Filter function was utilized
6) Ggplot 2: Implementation of the Grammar of Graphics
6. Data Sets
Airbnb is an online marketplace that enables people to list, find, then rent vacation homes.
Summary information and metrics for listings in Los Angeles from Jan.2008 to Aug. 2016:
http://insideairbnb.com/get-the-data.html
• Year: 2008-2016
• Host
• Guest
• Price
• Location
• House Type
• Review
Key Variables
7. Shiny app basics
1) Create a Shiny app with dashboard
File 1: Global <- library(shinydashboard)
File 2: ui <- dashboardPage()
File 3: server <- function(input, output, session) {}
RunApp will appear
2) Create tabs in dashboard
File > New Project > New Directory >
8. Heat Map: average price by county
Choroplethr : Creation of Choropleth Maps in R
Choropleths are thematic maps where geographic are colored according to specific metric
ChoroplethrMaps: maps used by the choroplethr package : counties in LA region
Note: zip code was converted to flip code as package only read flip code instead of zip code
12. Animation with ggplot2 and Magick
Server.R: Make a Plot>>Save as Image>>Run in Loop>
Convert the Images into GIF using Imagemagick>>Run the GIF
UI.R:
17. Summary
State-of-the-Art visualization helps users understand the dependency and factors
influencing the data set.
GoogleVis connects directly to Google Analytics API. No web development knowledge is
required for the user.
Full user control on the dynamics of the dashboard.
User-friendly dashboard allows users freely explore the information and look for the
desired target.
Utilizing animation technique, user can have a better understanding of the information.