DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Tips and Tricks for Efficient Coding in R
  • How to Get a Non-Programmer Started with R
  • Python vs. R: A Comparison of Machine Learning in the Medical Industry
  • How to Rectify R Package Error in Android Studio

Trending

  • Advanced Error Handling and Retry Patterns in Enterprise REST Integrations
  • Persistent Memory for AI Agents Using LangChain's Deep Agents
  • 5 AI Security Incidents That Broke Things in Production (and What They Have in Common)
  • Alternative Structured Concurrency
  1. DZone
  2. Coding
  3. Languages
  4. R With PowerBI: A Step-by-Step Guide

R With PowerBI: A Step-by-Step Guide

An in-depth guide to integrating your R scripts with Microsoft's PowerBI software to create eye-popping visualizations for your data.

By 
Anindita Basak user avatar
Anindita Basak
·
Jun. 09, 16 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
24.2K Views

Join the DZone community and get the full member experience.

Join For Free

There's been a lot of interest everywhere on how to integrate R scripts with Microsoft PowerBI dashboards. Here is a step by step guide to this.

Lets assume that you have some readymade R code available, for example, with the ggplot2 library. Lets use the following scripts to perform analytics using CHOL data.

  1. Open R studio or R Package (CRAN) & install ggplot2 library first.

  2. Paste the following R script and execute it:
  3. install.packages(‘ggplot2’)
    library(ggplot2)
    chol <- read.table(url(“http://assets.datacamp.com/blog_assets/chol.txt&#8221;"), header = TRUE)
    #Take the column “AGE” from the “chol” dataset and make a histogram it
    qplot(chol$AGE , geom = “histogram”)
    ggplot(data-chol, aes(chol$AGE)) + geom_histogram()

    You should be able to see the visual output like this.

    Histogram

  4. Next, execute the following pieces of R code to find out the binwidth argument using the ‘qplot()‘ function:
  5. qplot(chol$AGE,
    geom = “histogram”,
    binwidth = 0.5)

    qplot.JPG

  6. Lets get some help from the hist() function in R:
  7. #Lets take help from hist() function
    qplot(chol$AGE,
    geom=”histogram”,
    binwidth = 0.5,
    main = “Histogram for Age”,
    xlab = “Age”,
    fill=I(“blue”))

    hist.JPG

  8. Now, add an I() function for nested colors:
  9. #Add col argument, I() function where nested color.
    qplot(chol$AGE,
    geom=”histogram”,
    binwidth = 0.5,
    main = “Histogram for Age”,
    xlab = “Age”,
    fill=I(“blue”),
    col=I(“red”))

    I func.JPG

  10. Next, adjust ggplot2 a little by using the following code:
  11. #Adjusting ggplot
    ggplot(data=chol, aes(chol$AGE)) +
    geom_histogram(breaks=seq(20, 50, by = 2),
    col=”red”,
    fill=”green”,
    alpha = .2) +
    labs(title=”Histogram for Age”) +
    labs(x=”Age”, y=”Count”) +
    xlim(c(18,52)) +
    ylim(c(0,30))

    adjustggplot

  12. Plot a bar graph with the following code:
  13. #Plotting Bar Graph
    qplot(chol$AGE,
    geom=”bar”,
    binwidth = 0.5,
    main = “Bar Graph for Mort”,
    xlab = “Mort”,
    fill=I(“Red”))

    bargraph.JPG

  14. Next, open the PowerBI desktop tool. You can download it for free from this link. Now, click on the Get Data tab to start exploring and connect with an R dataset. Rscript.JPG
  15. If you already have R installed on the same system as PowerBI, you just need to paste the R scripts in the code pen. Otherwise you need to install R in the system where you are using the PowerBI desktop like this:

    Rexe

  16. Next, you can also choose the ‘custom R visual’ in PowerBI desktop visualizations and provide the required R scripts to build visuals and finally click ‘Run’.
  17. RPBI.JPG

  18. Build all the R function visuals by following the same steps and save the dashboard.
  19. Dashboard

  20. You can refresh an R script in Power BI Desktop. When you refresh an R script, Power BI Desktop runs the R script again in the Power BI Desktop environment.

Related Refcard:

R Essentials

R (programming language)

Published at DZone with permission of Anindita Basak. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Tips and Tricks for Efficient Coding in R
  • How to Get a Non-Programmer Started with R
  • Python vs. R: A Comparison of Machine Learning in the Medical Industry
  • How to Rectify R Package Error in Android Studio

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook