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

Pass field parameter to R script

I'm currently using field parameters to create dynamics PowerBI graphs. Works GREAT!

 

And I'm using R Visual Objects to show ggplot2 graphs with PowerBI data. It works GREAT too!! I just need to add the field to the visual objetc as with any other. I.E: I add the fields 'age' and 'hour' from my PowerBI data, and refer them in my ggplot:

 
ggplot(dataset, aes(x = age, y = hour...

But If I use a Field Parameter, it does not work
 
Any ideas on how to refer them?

 

2 REPLIES 2
Anonymous
Not applicable

Hi @Francisco_G_Cal ,

Did you get any error message? Could you please share the related R script with us for the further investigation? By the way, is there any space or special character in your field parameter name? It need to be enclosed in backticks in R if the column names include spaces or special characters. The following one is the thread which has the similar problem as yours, hope it can help you resolve the problem.

r - Unable to plot ggplot graph on Power BI - Stack Overflow

library(dplyr)

df <- tibble(
  incident_date = dataset$`Incident Date`,
  incident_regular = dataset$`# Incident - Regular`
)

Regressor = lm(formula = incident_regular ~ incident_date, data = df)

ggplot(df) +
  geom_point(aes(x = incident_date, y = incident_regular), color ='red') +
  geom_line(aes(x = incident_date, y = predict(Regressor, new data = df)), color ='blue') +
  ggtitle('Incident Count Prediction') +
  xlab('Incident Date') +
  ylab('Number of Incident')

Best Regards

I have no problem for drawing my ggplot in R.

Theese are the vars I add to the R Script Object

 

Values.jpg

The last one, 'Numericas', is a FIELD PARAMETER

This is my code (the commented lines are created by PowerBI)

 

# El código siguiente, que crea un dataframe y quita las filas duplicadas, siempre se ejecuta y actúa como un preámbulo del script: 

# dataset <- data.frame(Accesos, Edad, Hora)
# dataset <- unique(dataset)

# Pegue o escriba aquí el código de script:

library(ggplot2)

color_palette <- colorRampPalette(c("steelblue", "darkblue"))(length(dataset$Accesos))

# Crear el scatterplot con ggplot2
ggplot(dataset, aes(x = Edad, y = Hora, size = Accesos, alpha = Accesos, color = Accesos)) +
  geom_point(stroke = NA) +
  scale_size_continuous(range = c(2, 10)) +
  scale_alpha_continuous(range = c(0.1, 0.8)) +
  scale_color_gradientn(colors = color_palette) +  # Aplicar la paleta de colores
  labs(x = "Edad", y = "Hora", title = colnames(dataset))

 

And it works perfectly:

 

ggplot.jpg

But, if instead a field value, I use the Field Parameter

 

ggplot(dataset, aes(x = Edad, y = Numericas, size = Accesos, alpha = Accesos, color = Accesos)) +
 
I get this error:
Error Message:
Error del script R.
Error in `geom_point()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error:
! objeto 'Numericas' no encontrado
 
It says 'object 'Numericas' not found
 
So, is there a way to use 'Numericas'?
 

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.