R Tutorial : Constructing rbokeh Layers (Part 2)

Learn how to build layered visualizations with rbokeh in R using ly_ functions. The tutorial demonstrates scatter plots with lypoints, then combines lylines and ly_points layers to show GDP per capita trends for Australia and New Zealand, with customizable legends and figure attributes.
Chapters
Now that you have become familiar with the concept of layers in R Bokeh and how the plots are constructed, let's see some more layers. R Boket provides a wide variety of functions which are also known as layers. Basically, all the layers start with LY underscore followed by the type of the layer. In this course we will focus on some of the most common layers, mainly the ones to create scatter plots, Lines, bar charts, histograms now let's see an example using a subset of the Gapminder data in 1982. By filtering the Gapminder data by year 1982, you can see that the resulting data frame contains 142 entries with one row per country. Now suppose you want to see the relation between life expectancy and GDP per capita in 1982. A scatter plot will be a good choice to see all the data points. First you need to initialize a figure. Then you need to create a layer LY points and pass the required GDP per capita on the X axis, life expectancy on the Y axis and the filter data frame that underscore 1982 to the data argument. Notice that the resulting plot includes a point for each country and it shows that there could be a relation between the life expectancy and the GDP per capita. Now as you saw the lines layer and the points layer, you will see how to combine both in one figure. Let's take the records of Australia and New Zealand by filtering the gapminder data using the continent Equal Equal Oceania. The resulting data frame will include the data of the two countries in all the years. Now we would like to see the change of GDP per capita in the two countries over time. To plot multiple layers, you can pass the dataochinia to the data argument in figure. This will tell all the subsequent layers to use this data frame. Instead of specifying the data in each layer independently, which is still a valid option, then you can add a lines layer using Lylines. You will need to specify the X argument as the year and the Y as the GDP per capita and you can use the color to distinguish between the countries. In the next chapter you will learn more about the use of colors in different layers. To add markers, you can add a points layer by using the Pipe operator and adding LY underscore points with similar arguments. Notice that the legend location is specified as bottom right to change the default legend boost position. This is one of the figure attributes and you will learn more about them in chapter two. The resulting plot shows you how the gap in the GDP per capita increased with time between the two countries. Now it's time to try more examples.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







