Forum Discussion
Dynamically place text in R Script visual
- Anonymous3 years ago
After a bit of additional analysis, I found the issue. On my Power BI page, I use a number parameter slider which feeds a topN function to limit the number of data points plotted. Since I can't pass the parameter directly as a scalar constant, I set the size of the unwanted points to null. This causes the min() and max() functions to return NA.
My solution was to filter the dataset data frame before calculating min and max for my axes.Here's the code, FWIW:
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:# dataset <- data.frame(Vendor, Market Share, Growth, Revenue YoY, Top Vendor Revenue)# dataset <- unique(dataset)# Paste or type your script code here:# Load required librarieslibrary(tidyverse)library(scales)library(ggrepel)# Filter and format datasetdataset <- dataset %>%filter(!grepl('^Other ', .$Vendor )) %>% # Remove 'Other Vendors' from outputfilter(.$`Top Vendor Revenue` > 1) # Workaround due to fact PBI does not allow variables to be passed to R# Compute axis limites from datasetxmin <- 0xmax <- max(max(dataset$`Market Share`), 0.25)ymin <- min(dataset$`Growth`)ymax <- max(dataset$`Growth`)
Anonymous , Make sure your calculation are done within canvas(Visual), you are not doing page on power bi page
amitchandak I don't know what your reply means. I am using Power BI Desktop. I am using the built-in R script visualization. All my code is entered in the R script editor that is part of the R script visualization. The ggplot bubble chart I have created works and displays properly. The issue is that I am trying to use a calculated variable to place a text annotation on the chart canvas, but it doesn't appear to be recognized. If I run the same code in RStudio, it does work.
Does that help?
- Anonymous3 years agoNot applicable
After a bit of additional analysis, I found the issue. On my Power BI page, I use a number parameter slider which feeds a topN function to limit the number of data points plotted. Since I can't pass the parameter directly as a scalar constant, I set the size of the unwanted points to null. This causes the min() and max() functions to return NA.
My solution was to filter the dataset data frame before calculating min and max for my axes.Here's the code, FWIW:
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:# dataset <- data.frame(Vendor, Market Share, Growth, Revenue YoY, Top Vendor Revenue)# dataset <- unique(dataset)# Paste or type your script code here:# Load required librarieslibrary(tidyverse)library(scales)library(ggrepel)# Filter and format datasetdataset <- dataset %>%filter(!grepl('^Other ', .$Vendor )) %>% # Remove 'Other Vendors' from outputfilter(.$`Top Vendor Revenue` > 1) # Workaround due to fact PBI does not allow variables to be passed to R# Compute axis limites from datasetxmin <- 0xmax <- max(max(dataset$`Market Share`), 0.25)ymin <- min(dataset$`Growth`)ymax <- max(dataset$`Growth`)