Skip to Content
Author's profile photo Former Member

My Journey With Predictive Analysis Custom R Scripts


In this rainy sunday, being sent out of home because some serious tidy-up and cleaning going on inside home 🙂

i decided i will find somewhere to grab a coffee, listen to some awesome music and explore possibilities with R programming.

Since i am not very proficient in coding, i will look for some ready code on the internet and will try to adapt it.

I believe some social media content will really make my demos and presentations shine, so let’s see what we can do with Facebook API.

Result component link is at the bottom of this page, ready to be used,

What we want to achieve? See this viz.

First Step :

Log on to FB, visit this page, click on “get access token” (dont forget to authorize for friends data) :

ScreenHunter_326 Mar. 09 14.19.jpg

Here’s the github link to the original code i found online. it gets your friend list and their friends to plot a network cluster to visualize their connections to each other. Will be intresting to try:

We have to wrap this inside a function, add a print to actually plot the graph, make the api key a variable so we can pass from the algorithm properties page.

ScreenHunter_327 Mar. 09 14.26.jpg

Now let’s configure our key and run the component :

ScreenHunter_330 Mar. 09 14.35.jpg

ScreenHunter_328 Mar. 09 14.30.jpg

Run the component and…!!!

ScreenHunter_329 Mar. 09 14.32.jpg

The code basically plots the clusters, and creates a legend to show names of people right on the center of each cluster. You chan tweak the code to change plot parameters which will probably make it look visually more appealing, like this  :

ScreenHunter_332 Mar. 09 15.12.jpg

Looking at the plot and names which i didnt include in the screenshot, i understand that they are mainly :

1) Work network

2) University friends

3) High-school friends,

4) Elementary school friends (yes we did find each other via facebook 🙂

5) Family

I believe that’s a simple enough example of what clustering is, understanding different subcategories amongst a big list.

My next aim will be to replicate something similar but using a “product page” from facebook, visualizing people who “liked” the page. Any help is highly apreciated

Here’s the re-usable component for SAP Predictive Analysis, download it and paste it into the apropriate folder which may look like

C:\Users\”usernamecomeshere”\SAP Predictive Components\RScript

Please note that the code is provided “as-is” and is not supported by SAP.

Happy coding 🙂

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Surya Kunju
      Surya Kunju


      This is a great use case when we want to use it in Telco and Banks (Could help in even detecting fraud) This comes built-in in our product SAP InfiniteInsight and is called Social Network Analysis



      Author's profile photo Former Member
      Former Member

      Excellent work friend!

      This totally kicks....

      Could you send me the r-script, i tried to recreate this and i got an error, i'm guessing there's something wrong with my script.

      Anyway, thanks for sharing. 😉

      Author's profile photo Venkata Ramana Paidi
      Venkata Ramana Paidi

      It is good article Alper. I cannot access your file  as it is showing  "oops- your bookmark is out of date! SAP Box has been retired."

      Could you please attach the file.

      Thanks & Regards,


      Author's profile photo Antoine CHABERT
      Antoine CHABERT

      Hi Alper, is the content still applicable to the recent releases of SAP PA? We are planning for content migration and we need to understand this. Thanks & regards Antoine