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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
annaY
Regular Visitor

Subset my data frame in power bi

Hi all,

 

I am trying to implement a custom plot in PBI, which runs 100% without issues in R on my machine, and am running into a lot of isses. I've originally created a data table for the data in R, but have exported it out as a csv file for PBI. My questions:

 

1) Is there a way for me to run my original data.table() script to make the data table in PBI? When I try that in the R script editor, I get the following error: "No image was created. The R code didn't reseult in the creation of any visuals. Make sure your R script results in a plot to the R default device."

 

This seems to imply that I need to go with my original approach of using the csv file?

 

2) I need to subset my data frame to make one layer at a time in ggplot2. In R this works, but when I run my R script in PBI I get errors. As an example, the code below works:

 

library(ggplot2)
ggplot() +
   geom_line(aes(x = my_date, y = value, lty = variable),
                     col = 'lightblue',
                       size = 1.0,
                      data = dataset)

 

But when I add a subset to the data frame it doesn't work any more!

 

ggplot() +
   geom_line(aes(x = my_date, y = value, lty = variable),
                     col = 'lightblue',
                       size = 1.0,
                      data = dataset[variable == "Plan"])

 

Here "Plan" is one level of my factor 'variable' (variable is the name of the column). I get an error as follows: "Error in '[.data.frame'[dataset, variable == "Plan"): object variable not found . Calls geom_line -> layer ->fortify -> [-> [data.frame...execution halted.

 

Can anyone provide some insight?

 

0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.