March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
02-23-2021 06:33 AM - last edited 02-23-2021 06:35 AM
A powerful Power BI R visual, matrix bubble chart, to analyze three measures (facts) with two selected dimensions.
One needs to have R installed on the computer or to the server / enabled in the cloud environment.
Here is a guide to get started: https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-r-visuals
Here is a link to some details: https://docs.microsoft.com/en-us/power-bi/visuals/service-r-visuals
This could be an example from the car industry. The question could be what bundles we want to offer with what products and how should we price the product & bundle combinations.
See my blog post for an example use case:
https://www.plainlyresults.com/blog/power-bi-r-matrix-bubble-chart-sales-opportunity-analysis/
Add in your Power BI R visual the code below the "Paste or type your script code here:" text.
#change lib path to were you have ggplot2 and scales installed
library(ggplot2, lib="D:/Program Files/R/R-3.6.3/library")
require(ggplot2)
library(scales, lib="D:/Program Files/R/R-3.6.3/library")
#change columns Product, Free_feature_bundle, dataset$... to your columns in the Power BI model selected to the R visual
ggplot(dataset, aes(x = Product, y = Free_feature_bundle, label = paste(round(dataset$Opportunity_count, digits=0), round(dataset$Hitrate_perc, digits=2)*100, round(dataset$Margin_perc, digits=2)*100, sep=";"))) +
geom_point(shape = 21, aes(size = round(dataset$Opportunity_count, digits=0) , fill = round(dataset$Hitrate_perc, digits=2)*100, color = round(dataset$Margin_perc, digits=2)*100, stroke = 3)) +
geom_text(hjust = 1, size = 4) +
scale_size(range = c(15,50)) + #scaling of the bubbles
theme_bw()+ scale_fill_gradient2("Hitrate % (fill)", low=muted("red"), high=muted("green"), midpoint =
mean(dataset$Hitrate_perc*100)) +theme_bw()+ scale_color_gradient2("Margin % (edges)", low=muted("red"),
high=muted("green"), midpoint = mean(dataset$Margin_perc*100)) + labs(size = "Number of opportunities (size)")
Hi,
I am trying to create a chart but I am stuck while running the script, the error is "
can you please help me to proceed?
Thanks,
Neha
"
@nehajadhav166 Assuming that ggplot2 and scales packages are installed, try modifying the R script and remove or comment out the lib= instructions, like this:
# if R is already in your path, you do not need the lib= instruction
library(ggplot2) #, lib="D:/Program Files/R/R-3.6.3/library")
require(ggplot2)
library(scales) #, lib="D:/Program Files/R/R-3.6.3/library")
That worked for me.
Good luck!