R with SAP Analytics Cloud : Part One

Rajkumar Benny
SAP Analytics Cloud
4 min readSep 19, 2019

In this segment, I will be covering about the programming language R with respect to the tool SAC Analytics Cloud, and how to go about it.

First and foremost, what is R programming language and why do we need it?

R is a programming language, exclusively for statistics, that was developed by scientists in the University of Auckland. It’s open source and is widely popular among research circles. Even in popular culture, it’s gaining traction, with popular news media circles like BBC ,having their data visualization team using it for their purposes. You can explore more about it with the link below — https://medium.com/bbc-visual-and-data-journalism/how-the-bbc-visual-and-data-journalism-team-works-with-graphics-in-r-ed0b35693535 .

That being said, in this segment, I will cover how to apply the ggplot package with respect to creating some neat visualizations in SAP Analytics Cloud.

For a complete beginner, you may wonder — why do I even need this integration in the first place ? Doesn’t SAP Analytics Cloud have all that I require ? While SAC is a powerful enough tool and lets you create visualizations with a drag and drop interface, note that behind every chart and every widget in the story, are a chunk of code that made them in the first place.

While SAP Analytics Cloud has ample visualizations that needn’t require editing the way they look or their functionality, there may come a time when you need to add additional features to the visualization, or perform analysis to them, and the R programming language comes in handy — because it has a myriad of packages that are dedicated specifically to analysis and visualizations. My personal favorite is the dplyr package : A package that makes filtering the data easier.

Let me demonstrate with an example. I will not be covering all the concepts in R since it’s long, exhaustive and there are plenty of tutorials over the internet that covers them, but I will only cover the concepts that are necessary in SAP Analytics Cloud.

I took a dummy sports data that I have made with the help of https://mockaroo.com/ . Then, I add three dimensions, namely, the Player’s ID, his name and the team he belongs to as the Rows.

Next, I open the Script, wherein we start typing the R code that we require.

To start the script, we first load the ggplot2 package with library(ggplot2) .

Next, to plot the visualization using ggplot, I must first ensure that my corresponding dataset is a data frame — which is what I did with the help of — is. data. frame(Random sports data.csv) .

What is a data frame ? Why do we need it ?

A data frame is basically a structure in R that can hold more than one data type. It’s basically the antithesis to Matrix, another data structure in R, which can hold only one specific data type. It is one of the most common data structures in R, and we will be using it for most of our visualization purposes.

Let me present you the different data types using the GIF below —

I just touched upon the 5 main data types used in R , namely, integer, numeric, complex. character and logical. If you’re looking to delve further into learning about all the datatypes, including raw, the sixth data type, you could find a plethora of articles in the web for them.

Lastly, time to plot the given data !

ggplot plots its visualization after mentioning two crucial pieces of information !

One is the dataset, which I mentioned in data , and the other is the aesthetics, which I mentioned as aes, which incorporates the visual characteristics, most importantly, the shape of the points used, the type of lines involved, the color and the size.

I represented the Player’s Name along the X axis, and their Rebounds count along the Y axis. The type of visualization is point visualization, which I mentioned by geom_point() .

There’s a blurry preview. Why don’t we apply the changes and check for ourselves !

Lastly, I attempt to differentiate the different players based on the team, and so I used the color aesthetic. I also increased the size of the point visualization to 4.

I hope that this has given a fair idea on how R can be integrated into SAP Analytics Cloud. In the next blog, I will delve into more visualizations and features of R that we can use !

--

--