Plotly basic charts – exercises


Plotly’s R graphing library makes interactive, publication-quality web graphs. More specifically it gives us the ability to make line plots, scatter plots, area charts, bar charts, error bars, box plots, histograms, heatmaps, subplots, multiple-axes, and 3D charts.

In this tutorial we are going to make a first step in plotly’s world by learning to create some basic charts enhanced with proper layouts that the plotly package provides.

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.

For other parts of this series follow the tag plotly visualizations

Exercise 1

Create a line plot of x and y. HINT: Use mode = "lines".

Exercise 2

Create a scatter plot of x and y. HINT: Use mode = "markers".

Exercise 3

Create a bar plot of x and y. HINT: Use type = "bar".

Exercise 4

Create a bubble chart of x and y. Choose size and color of your choice for every marker. HINT: Use size and color.

Exercise 5

Create a heatmap of the “volcano” dataset. HINT: Use z.

Learn more about using plotly in the online course Data Science and Machine Learning Bootcamp with R. Besides a comprehensive overview of R and machine learning, this course offers a specific section on Plotly. More than 17,000 students already took this course!

Exercise 6

Create an area plot of x and y. HINT: Use fill = "tozeroy".

Exercise 7

Add y3 to the scatterplot of Exercise 2. Then create your scatter plot with trace. HINT: Use add_trace().

Exercise 8

Transform the trace you added in Exercise 7 into legend with coordinates(1,1) and red color. HINT: Use layout().

Exercise 9

Add axes to the scatterplot you built in Exercise 2. Set nticks to 40, add showline, give a title and set mirror to “all”. HINT: Use list().

Exercise 10

Now add showgrid, zeroline, set nticks to 20 and remove showline to spot the differences.