The ggvis package is used to make interactive data visualizations. The fact that it combines shiny’s reactive programming model and dplyr’s grammar of data transformation make it a useful tool for data scientists.
This package may allows us to implement features like interactivity, but on the other hand every interactive ggvis plot must be connected to a running R session.
Before proceeding, please follow our short tutorial.
Look at the examples given and try to understand the logic behind them. Then try to solve the exercises below using R and without looking at the answers. Then check the solutions.
to check your answers.
Exercise 1
Create a list which will include the variables “Horsepower” and “MPG.city” of the “Cars93” data set and make a scatterplot. HINT: Use ggvis()
and layer_points()
.
Exercise 2
Add a slider to the scatterplot of Exercise 1 that sets the point size from 10 to 100. HINT: Use input_slider()
.
- Work extensively with the ggvis package and its functionality
- Learn what visualizations exist for your specific use case
- And much more
Exercise 3
Add a slider to the scatterplot of Exercise 1 that sets the point opacity
from 0 to 1. HINT: Use input_slider()
.
Exercise 4
Create a histogram of the variable “Horsepower” of the “Cars93” data set. HINT: Use layer_histograms()
.
Exercise 5
Set the width
and the center
of the histogram bins you just created to 10.
Exercise 6
Add 2 sliders to the histogram you just created, one for width
and the other for center
with values from 0 to 10 and set the step
to 1. HINT: Use input_slider()
.
Exercise 7
Add the labels “Width” and “Center” to the two sliders respectively. HINT: Use label
.
Exercise 8
Create a scatterplot of the variables “Horsepower” and “MPG.city” of the “Cars93” dataset with size
= 10 and opacity
= 0.5.
Exercise 9
Add to the scatterplot you just created a function which will set the size
with the left and right keyboard controls. HINT: Use left_right()
.
Exercise 10
Add interactivity to the scatterplot you just created using a function that shows the value of the “Horsepower” when you “mouseover” a certain point. HINT: Use add_tooltip()
.
Leave a Reply