Want to learn more? Take the full course at https://learn.datacamp.com/courses/in... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Hi, I'm Adam Loy, and I'll be your instructor for this course on animated and linked graphics in R.
Interacting with your graphics, or watching them change over time, allows you to gain insight that may be difficult to gain from static plots, and allows people to explore your analysis without pouring through many different views. For example, it's far easier to understand how the relationship between country-level CO2 emissions and income evolves over time using an animation than a large number of static plots.
In this course, you'll learn how to explore multivariate relationships using both animation and interactivity. Before building more complicated graphics, let's review a few basic ideas about plotly.
In this course, we will use plotly, a visualization library for interactive and dynamic web-based graphics. While there are other visualization libraries available for R, plotly is still under heavy development, so it's a great time to learn how to harness its power.
Before you start creating graphics, it's important to think carefully about what type of graphic best suits your purpose: static, interactive, or dynamic. To highlight features of each type of graphic, let's consider creating a graphic to explore the price of the iShares all countries world index, an ETF that tracks the global stock market.
A static plot remains permanently fixed after you create it. For example, you can create a time series plot of the closing price of the All Countries World Index over the course of 2017 for inclusion in a report.
In contrast, an interactive graphic can be updated based on actions performed by the user. In our example, an interactive graphic allows us to hover above a specific date to see the closing price or to zoom in and focus only on the fourth quarter. Simple interactions vastly increase your ability to explore the story your data are telling. Soon you'll review how easy plotly makes it add these simple, but powerful, interactions to your graphics.
Unlike interactive graphics, dynamic graphics change automatically. One example is an animation showing how the All Countries World Index changed throughout the course of 2017. Similarly, we could design a dynamic graphic to update every five minutes over the course of a trading day to communicate the current price of the fund. The key here is that neither of these examples requires user input once the code to generate the graphics are written.
To review the basics of plotly, let's create an interactive time series of the closing prices of the All Country World Index in 2017. In order to create the time series plot, we need to map Date to the x-axis and Close to the y-axis.
After loading the plotly package,
we pipe our data into the `plot_ly` function, which creates the HTML canvas on which our plot is rendered, much like the ggplot() base-layer in static graphics. Here, we map Date to the x-axis and Close to the y-axis. Notice that we use a tilde to specify that we are mapping a variable from the data set to an aesthetic parameter rather than specifying a specific value. Finally, we add a line trace using the `add_lines()` function, just like adding a layer in ggplot2, but using the pipe operator.
As you can see, the resulting graphic uses a line to connect the ordered pairs of dates and closing prices. Additionally, the icons at the top of the graphic highlight ways that you can interact with your plot. During the exercises be sure to explore these interactions so that you see the power of plotly!
Before diving deeper into plotly, let's practice the basics.
On this page of the site you can watch the video online R Tutorial: Intermediate Interactive Data Visualization with plotly in R with a duration of hours minute second in good quality, which was uploaded by the user DataCamp 01 March 2020, share the link with friends and acquaintances, this video has already been watched 832 times on youtube and it was liked by 11 viewers. Enjoy your viewing!