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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
carlossantiago
Frequent Visitor

Plotting R charts in Power BI

Hi guys,

 

My scripts just don`t work. I've tryed a very simple example in RStudio and Power BI R Script Editor.

 

The script is:

a<- c(1:10)
b<- c(20:29)
c[1]<-sum(a)
c[2]<-sum(b)
barplot(c)
title("my bar")

 

See below the outputs I have:

 

In R Studio:

Capture1.JPG

R Script Editor:

 

Capture2.JPG

 

Does anyone can help me to make it work?

 

 

Thanks,

 

 

Carlos Santiago

1 ACCEPTED SOLUTION
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @carlossantiago,

I try to reproduce your scenario and get expected result, please review the steps below.

1. I create the bar chart in R as follows. Please add the command: c<-c(0,0), otherwise, it will returns the error message like yours.

a<- c(1:10)
b<- c(20:29)
c<-c(0,0)
c[1]<-sum(a)
c[2]<-sum(b)
barplot(c)
title("my bar")



1.PNG

2. Then I will get the same result in Power BI desktop. 

2.1 You must import the data before you create visual. So I click "Enter Data", type the following data.

2.PNG

2.2 Click R visual->select the a,b as value field, it will create the dataset automatically(please see the part highlighted in black box), which is a Power BI by design behavior. Then type T script(highlighted in yellow box), you will get expected result.

2.PNG3.png      

c<-c(0,0)
c[1]<-sum(dataset[,1])
c[2]<-sum(dataset[,2])
barplot(c)
title("my bar")


From your screenshot, what are c3 and c2?

Best Regards,
Angelia

View solution in original post

1 REPLY 1
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @carlossantiago,

I try to reproduce your scenario and get expected result, please review the steps below.

1. I create the bar chart in R as follows. Please add the command: c<-c(0,0), otherwise, it will returns the error message like yours.

a<- c(1:10)
b<- c(20:29)
c<-c(0,0)
c[1]<-sum(a)
c[2]<-sum(b)
barplot(c)
title("my bar")



1.PNG

2. Then I will get the same result in Power BI desktop. 

2.1 You must import the data before you create visual. So I click "Enter Data", type the following data.

2.PNG

2.2 Click R visual->select the a,b as value field, it will create the dataset automatically(please see the part highlighted in black box), which is a Power BI by design behavior. Then type T script(highlighted in yellow box), you will get expected result.

2.PNG3.png      

c<-c(0,0)
c[1]<-sum(dataset[,1])
c[2]<-sum(dataset[,2])
barplot(c)
title("my bar")


From your screenshot, what are c3 and c2?

Best Regards,
Angelia

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.