Technical Articles
Creation of Increment and Decrement Indicator Arrow in SAP Analytics Cloud using R Visualization
R Visualization in SAP Analytics Cloud can be used to create charts which are not directly available in SAP Analytics Cloud. In this blog I am explaining how to create an Increment and Decrement Indicator Arrow in SAP Analytics Cloud using R Visualization feature.
Step-1: Either create a new Story or open an existing story in edit mode. Navigate to “Insert” and click on “+” button. Click on “R Visualization”.
Step-2: Add the Model as Input Data in Builder.
Step-3: Click on “Add Script” in Builder.
Step-4: Expand the window.
Step-5: There are 4 panes in the window i.e. Editor, Environment, Console and Preview.
The R code is written in the Editor and then executed. Any error message is displayed in Console. If no errors, the visualization is displayed in Preview.
With R, many plotting symbols are available which can be be used using the graphical argument ‘PCH‘
Below is the list of available plotting symbols.
PCH | Point Symbol | PCH | Point Symbol | |
0 | square | 13 | circle cross | |
1 | circle | 14 | square and triangle down | |
2 | triangle point up | 15 | filled square | |
3 | plus | 16 | filled circle | |
4 | cross | 17 | filled triangle point-up | |
5 | diamond | 18 | filled diamond | |
6 | triangle point down | 19 | solid circle | |
7 | square cross | 20 | bullet (smaller circle) | |
8 | star | 21 | filled circle blue | |
9 | diamond plus | 22 | filled square blue | |
10 | circle plus | 23 | filled diamond blue | |
11 | triangles up and down | 24 | filled triangle point-up blue | |
12 | square plus | 25 | filled triangle point down blue |
The other arguments required to customize the symbols are as below.
col: Color to be used for points
bg: The background or Fill color for open plot symbols. It can be used only when pch = 21:25
cex: The size for pch symbols
lwd: The line width for the plotting symbols.
R Code for Increment/Decrement Indicator:
x<-c(1)
data1<-Sample_Model$`Profit 2020`
plot(x,xaxt=’n’,yaxt=’n’,
frame.plot=FALSE,ann=FALSE,
pch=ifelse(data1>=Sample_Model$`Profit 2019`,24,25),cex=20,
col=ifelse(data1>=Sample_Model$`Profit 2019`,”green”,”red”),
bg=ifelse(data1>=Sample_Model$`Profit 2019`,”green”,”red”),lwd=1)
Step-6: After submitting the code, the indicator is included in the story.
Usage:
The indicators can be further customized by including variance values as shown below. This helps provide more insight to the underlying data to the end users.
In similar ways, changing the pch values other indicators can be included in the SAC story.
Technical inputs shared by @Suvam Dey
References : http://www.sthda.com/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r
Fantastic: I love it .... why not add a little demo video in your blog with the final result?
Thanks 🙂 I will add the video.
Nice one - thanks for sharing 🙂
Thanks Adem !
Pleas share video, if possible. Many Thanks
Very useful, thank you!
Is it possible to add filters directly in the R-script? For exaample a specific customer number or something.