<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/r-graphs-and-tables-in-power-bi-desktop/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/"> R – TomazTsql</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Power BI Desktop enable users to use <a target="_blank" rel="nofollow" href="https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-r-visuals/">R script visual</a> for adding custom visualization generated with R language – regardless of R package used. Before using R script visual, you will need to enable it by setting path to R Engine on your client in the global options. Once this is done, you will be able to enhance your Power BI reports using R visualizations.</p>
<p><img sizes="(max-width: 343px) 100vw, 343px" data-image-description="" data-orig-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/1450757873470.jpg?resize=343%2C297&amp;ssl=1" data-orig-size="460,398" data-image-title="1450757873470" class="wp-image-3065" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="3065" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/attachment/1450757873470/#main" alt="1450757873470" data-medium-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/1450757873470.jpg?resize=343%2C297&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/1450757873470.jpg?resize=343%2C297&amp;ssl=1?w=460" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/1450757873470.jpg?resize=343%2C297&ssl=1"></p>
<p>My personal favorite R packages I like to use in Power BI are shiny, plotly, ggplot2, googleVis, ggiraph, rCharts and d3js.  Apart from finding the package for data visualization where you feel home, one of the very great thing I find with Power BI + R is the ability to have visualizations created dynamically (more or less like if you would be using plotly or shiny)  with slicers and selectors. And this makes data exploration, data wrangling so much easier.</p>
<p>With October 2016 Power BI custom visuals got <a target="_blank" rel="nofollow" href="https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-r-powered-custom-visuals/">additional 7 R visuals</a> to the family (check Power BI <a target="_blank" rel="nofollow" href="https://app.powerbi.com/visuals/">Visuals Gallery</a> and fall in love with your favorite one<img alt="🙂" class="wp-smiley" src="https://i0.wp.com/s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png?w=456&ssl=1" data-recalc-dims="1"> ).</p>
<p><img sizes="(max-width: 700px) 100vw, 700px" data-image-description="" data-orig-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi.png?w=456&amp;ssl=1" data-orig-size="1156,460" data-image-title="2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi" data-comments-opened="1" class="wp-image-3083" data-recalc-dims="1" data-attachment-id="3083" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi/#main" alt="2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi" data-medium-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi.png?w=456&amp;ssl=1?w=700" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-09_26_55-visuals-gallery-_-microsoft-power-bi.png?w=456&ssl=1"></p>
<p>Upon using any of the additional R visuals, Power BI will – prior to importing the additional visualizations – ask for installing all the missing packages, as well as inform you of any incompatibility between R engine and package.</p>
<p>So how easy is to create R visualization in Power BI?  Let us first import data to Power BI from SQL Server. I have generated a sample data-set for this demo. Data and all the samples are available at <a target="_blank" rel="nofollow" href="https://github.com/tomaztk/PowerBI_R_visual">Github</a>.</p>
<p><img sizes="(max-width: 246px) 100vw, 246px" data-image-description="" data-orig-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s.png?resize=246%2C361&amp;ssl=1" data-orig-size="447,656" data-image-title="2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s" data-comments-opened="1" class="wp-image-3089" data-recalc-dims="1" data-attachment-id="3089" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s/#main" alt="2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s" data-medium-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s.png?resize=246%2C361&amp;ssl=1?w=204" data-large-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s.png?resize=246%2C361&amp;ssl=1?w=447" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_32_26-preparing-data-sql-sicn-kastrun-plan-spar_si01017988-69_-microsoft-sql-s.png?resize=246%2C361&ssl=1"></p>
<p>With sample data-set I have created a simple data visualization with slicers using Power BI.</p>
<p><img sizes="(max-width: 700px) 100vw, 700px" data-image-description="" data-orig-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop1.png?w=456&amp;ssl=1" data-orig-size="1452,811" data-image-title="2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop" data-comments-opened="1" class="wp-image-3097" data-recalc-dims="1" data-attachment-id="3097" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop-2/#main" alt="2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop" data-medium-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop1.png?w=456&amp;ssl=1?w=300" data-large-file="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop1.png?w=456&amp;ssl=1?w=700" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop1.png?w=456&ssl=1"></p>
<p>Now, the same visualization using R.</p>
<p><img sizes="(max-width: 700px) 100vw, 700px" data-image-description="" data-orig-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2.png?w=456&amp;ssl=1" data-orig-size="1424,816" data-image-title="2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2" data-comments-opened="1" class="wp-image-3098" data-recalc-dims="1" data-attachment-id="3098" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2/#main" alt="2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2" data-medium-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2.png?w=456&amp;ssl=1?w=700" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_34_01-sample_powerbi_r-power-bi-desktop_2.png?w=456&ssl=1"></p>
<p>Note that I have used same slicers (Year = 2016, Month = 2) and R graph (using ggplot2) was able to dynamically  visualize the numbers. So this mean, that any R visualized graph can be navigated and dynamically updated, which is absolutely great, especially in cases when you do data exploration. Following R code was used:</p>
<pre>library(ggplot2)
ggplot(data=dataset, aes(x=Day, y=Value)) +  geom_line(aes(color=&quot;red&quot;)) + 
ggtitle(&quot;Value by day&quot;) + theme(legend.position = &quot;none&quot;) + 
theme(panel.background = element_rect(fill = &quot;white&quot;, color = &quot;lightgray&quot;, size = 1))</pre>
<p>with additional dataset conversion to data.frame done automatically.</p>
<p><img sizes="(max-width: 700px) 100vw, 700px" data-image-description="" data-orig-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code.png?w=456&amp;ssl=1" data-orig-size="1452,297" data-image-title="2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code" data-comments-opened="1" class="wp-image-3102" data-recalc-dims="1" data-attachment-id="3102" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code/#main" alt="2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code" data-medium-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code.png?w=456&amp;ssl=1?w=700" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-11_57_51-sample_powerbi_r-power-bi-desktop_code.png?w=456&ssl=1"></p>
<p>Where it get’s tricky is if you want to return the R data.frame into your Power BI page in form of a table (imagine you want some results to your graph or that you are calculating some statistics). Well, Power BI does not allow returning tables from R script visual. Unless, table is an image (that is, in a “form” of a visualized “graph”).</p>
<p>So I manage to create a table as a graph using R and gplot function from ggplot2 package.</p>
<p><img sizes="(max-width: 700px) 100vw, 700px" data-image-description="" data-orig-file="https://i1.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop.png?w=456&amp;ssl=1" data-orig-size="1461,831" data-image-title="2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop" data-comments-opened="1" class="wp-image-3120" data-recalc-dims="1" data-attachment-id="3120" data-permalink="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop/#main" alt="2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop" data-medium-file="https://i1.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop.png?w=456&amp;ssl=1?w=300" data-large-file="https://i1.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop.png?w=456&amp;ssl=1?w=700" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i1.wp.com/tomaztsql.files.wordpress.com/2016/12/2016-12-18-12_40_32-sample_powerbi_r-power-bi-desktop.png?w=456&ssl=1"></p>
<p>The best part of this table is, that is dynamically changed based on selection on graphs or slicers. The downside is, that it can not be scrolled within the object. So if you end up with bigger table, you have to tweak the font size or show table aggregated or grouped.  In my opinion, I would not change R created table with Power BI table, because Power BI table is simply better and easier to create and maintain. But I would definitely recommend using R tables to support your R visuals. For example: If you are generating clusters using R in power BI, use R generated table to expose additional statistics on clusters.</p>
<p>The code for generating this R table is:</p>
<pre>library(gridExtra)
library(ggplot2)

qplot(x=1:5, y=1:5, geom = &quot;blank&quot;) + 
theme(line = element_blank(), text = element_blank()) + 
annotation_custom(grob=tableGrob(dataset))</pre>
<p>Script generated blank plot, where custom annotation is added with function grob. And this is our data.frame from dataset and is displayed on top of empty graph.In addition to “remove” the background blank graph, blank line and text is added:</p>
<pre>theme(line = element_blank(), text = element_blank())</pre>
<p> </p>
<p>As always, sample, code and data-set is available at <a target="_blank" rel="nofollow" href="https://github.com/tomaztk/PowerBI_R_visual">Github</a>.</p>
<p>Happy PowerBI-Rrrring!</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomaztsql.wordpress.com/3057/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/tomaztsql.wordpress.com/3057/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://tomaztsql.wordpress.com/2016/12/18/r-graphs-and-tables-in-power-bi-desktop/"> R – TomazTsql</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/ej6RR6qtZvI"></a></div>