Blogs / SAP / SAP Analytics Cloud / R Visualizations / R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

May 10, 2019

SHARE

This blog series is about leveraging R Visualizations in SAP Analytics Cloud. In the previous blog, we learnt how to create R widgets in an analytic application and perform dynamic filtering on them. In this blog, let us see how to add interactive tooltips, data labels and other customizations to enhance the user experience in R charts of SAP Analytics Cloud.

The plotly library

While most R packages render visuals as PNG images, plotly being a javascript graphing library allows the user to create interactive charts. Here you can see the fully customized R Visualization using the plotly library.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

Now, let us see how to add a simple plotly chart and customize it for SAP Analytics Cloud Stories / Applications to suit our requirements. Though the customizations discussed in this blog can be used for all chart types, for easier understanding, we’ll consider using a bar chart.

Adding interactivity to R widgets using the plotly library

plot_ly() function is used to plot various visualizations. The following script renders a simple bar chart. Refer to the previous blog to learn about configuring R widgets in SAP Analytics Cloud.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

Executing the script renders an unsorted bar chart along with tooltip. By default, the tooltip is configured to show the measure value and the name of the member.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

Also, there are various options in the mode barincluding zoom, export, pan, auto scale etc. It even allows the user to compare two data points on hover, like native charts.

Customizing R Widgets

Although the chart plotted using plot_lyprovides various features to the end user like mode bar, note that the chart currently looks drastically different from other native charts in any Story/App and also that the y-axis labels are cut by default as the label length is too large to fit.

One need not go through the hassle of these aesthetic discrepancies to leverage the capabilities of R in SAP Analytics Cloud. There are ways to extensively customize the looks of the chart as explained below.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

Plotly provides multiple functions and numerous tweak options that make the visualizations highly customizable. Along with the default plot_ly() function, let’s make use of layout() and config() functionalities to make it aesthetically appealing as the native ones.

1. Leveragingplot_ly() for interactivity

Following are the options that can be customized under plot_ly() function:

a. Sort

Use the function reorder() to sort bar based on a measure.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
b. Tooltip

Tooltip can be configured by assigning any measure to hoverinfo option.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
c. Bar Color

The color of the bar can be easily changed within marker option.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

2. Enhancing the plot using layout()

a. Margin

Margins can be customized within layout() function using margin option.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
b. Auto Size

autosize = Twill auto size the chart.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
c. Axis Line

Linewidth option is used to assign line width to axis.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
d. Axis Labels and Gridlines

You can remove axis labels by setting showticket labels to false and hide the gridlines by setting the option showgrid to false.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
e. Format Tooltip

The tooltip added previously can be formatted here using hoverlabel.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets
f. Font

Properties like color, family can also be changed.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

3. Customizing Data Labels

The function add_annotations() can be used to show any measure and can also be formatted using options like xanchor to align the data labels.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

4. Customizing Mode Bar

displayModeBar option is used to set the mode bar option using the config() function.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

The code above customizes R widgets in SAP Analytics Cloud, to resemble native charts. Apart from the options mentioned above, you can find plenty more for widget customizations here.

These customizations can also be applied to different chart types as shown below.

R Visualizations in SAP Analytics Cloud Series: 2 – Adding Interactivity and Customizations to R widgets

In the next blog of this series, we will look at how to dynamically swap, sort and rank visualizations in SAP Analytics Cloud using R.

Reach out to our team here if you are interested in evaluating if SAP Analytics Cloud is right for you.


Corporate HQ:
5920 Windhaven Pkwy, Plano, TX 75093

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

solutions@visualbi.com


Copyright © Visual BI Solutions Inc.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This!

Share this with your friends and colleagues!