Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Dynamically place text in R Script visual

Because Power BI is designed as a tool to be used interactively, it has many limitations on static data labels. To get around this issue, I'm using ggplot in an R Script visual to create a bubble cha...
  • Anonymous's avatar
    Anonymous
    3 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 libraries
    library(tidyverse)
    library(scales)
    library(ggrepel)

    # Filter and format dataset
    dataset <- dataset %>%
        filter(!grepl('^Other ', .$Vendor )) %>%    # Remove 'Other Vendors' from output
        filter(.$`Top Vendor Revenue` > 1)     # Workaround due to fact PBI does not allow variables to be passed to R

    # Compute axis limites from dataset
    xmin <- 0
    xmax <- max(max(dataset$`Market Share`), 0.25)
    ymin <- min(dataset$`Growth`)
    ymax <- max(dataset$`Growth`)