Skip to Content
Technical Articles

R Visualization for SAP Analytics Cloud – Understanding ggplot syntax – Part 1

When I ventured to learn some R programming language, especially for the purpose of creating some visualizations for SAP Analytics Cloud (SAC); I hit a roadblock, primarily for a couple of reasons.

  1. I had never learnt R programming language, like ever.
  2. I could not find an article on the SCN which I could refer for R, specific to SAC, for forever.

I did find a few articles over the web where I would find a code snippet. But with all code snippets; you should not just copy-paste it but one has to try and understand what the code is actually doing.

I had to skim through a lot of articles, to understand some of the basic statements in R. That being so, I thought of putting down some of my learnings in a blog which will help people like me create a few charts in SAC using R visualizations.

Throughout this blog, whenever I talk about R, i am talking about one of the libraries being used in R, ggplot2. Because this is primarily the library which we will use to create graphs in R within SAC.

If you are reading this, in all likelihood, you know we have an option of creating visualizations specific to your customer needs in SAC. You can create new charts that are not available with the standard SAC visualization options. This is done using the R programming language within SAP Analytics Cloud.

I am not going to delve deep into the definitions and explanations of how to use R within SAC. For this you can refer the below article.

Using R Visualizations within SAP Analytics Cloud

Lets start then…

Assign Data

The first step is to assign data and that is done using ggplot(df) where df is the dataframe.

Now using the aes() argument inside ggplot, we can define the aesthetics. The aes argument stands for aesthetics. Aesthetics such as X and Y axis, color, size, shape and stroke can be specified. Aesthetics is optional though. No plot will be drawn until we define the layers.

This is how the plot will be seen once u execute the below statement, where EmpMaster is your dataset.

EmpMaster data set contains information about the employees and their performance in their organization.

ggplot(EmpMaster)

 

ggplot(EmpMaster, aes(x=Performance, y=Headcount))

 

In the second part, we will add the layers and labels into our plot.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.