Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
bobbob123
Helper III
Helper III

PLOTLY Scatter plot using R in POWER BI

Hi,

 

I have the following dataset.

 

# dataset <- data.frame(EM, HM, SA,S,MA)  #All the elements in this dataframe are integers expect for S which is a string describing the groups.
# dataset <- unique(dataset)
 
I want to create a scatter plot using PLOTLY in R using POWER BI where x= SA and y = HM and legends = S.
 
This is what I have:
 
library(plotly)

fig <- plot_ly(data = dataset, x = ~dataset$SA, y = ~dataset$HM, fill=S)

fig
 
But this is not resulting in a visual. Is there something wrong with my code???
 
1 ACCEPTED SOLUTION

Hi @bobbob123 ,

 

Sorry to reply so late. Plotly lib is supported as part of HTML support for R powered Custom Visuals only, not R Visuals in general currently.

 

Plotly can only be used if it produces an IMAGE\PNG for R visuals in PBI. Not HTML.

 

If you want to create interactive visualizations using plotly. The only way you can do is to create a custom Power BI visualization and import it to your report. See these posts for a good introduction.

Interactive Charts using R and Power BI: Create Custom Visual Part 1 

Interactive Charts using R and Power BI: Create Custom Visual Part 2 

How to create R custom visual (html) in PowerBI 

 

And this is my test.

 

Screenshot 2022-04-20 145650.pngimage.pngimage.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @bobbob123 ,

 

The most current version of R supported on both Power BI Desktop and the Power BI service is version 3.4.4.

 

And please try the code:

 

library(plotly)

plot_ly(data = dataset, x = ~SA, y = ~HM,  type = "scatter", mode = "markers", color =~S)

 
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is what I get.

 

Error Message:
R script error.
Loading required package: ggplot2

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

last_plot

The following object is masked from 'package:stats':

filter

The following object is masked from 'package:graphics':

layout

Warning message:
replacing previous import 'vctrs::data_frame' by 'tibble::data_frame' when loading 'dplyr'
Error: unexpected symbol in "plot_ly(data = dataset, x = ~SA"
Execution halted

 

Hi @bobbob123 ,

 

Sorry to reply so late. Plotly lib is supported as part of HTML support for R powered Custom Visuals only, not R Visuals in general currently.

 

Plotly can only be used if it produces an IMAGE\PNG for R visuals in PBI. Not HTML.

 

If you want to create interactive visualizations using plotly. The only way you can do is to create a custom Power BI visualization and import it to your report. See these posts for a good introduction.

Interactive Charts using R and Power BI: Create Custom Visual Part 1 

Interactive Charts using R and Power BI: Create Custom Visual Part 2 

How to create R custom visual (html) in PowerBI 

 

And this is my test.

 

Screenshot 2022-04-20 145650.pngimage.pngimage.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You can take a look at this blog post. It describes how to add an interactive javascript Plotly Chart in Power BI. It's quite easy.

Kind regards,

Steve.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors