Open Side Menu
Skip to contentBrand Logo
Forums
Inspiration
Ideas
Communities
Blogs
Learning
Support
RegisterSign In
  1. Microsoft Fabric Community
  2. Power BI forums
  3. Galleries
  4. R Script Showcase
Sharon's avatar
Sharon
Microsoft Employee
10 years ago

Data Smoothing with Splines

Description Smoothing helps you to better visualize and understand noisy data   Prerequisites (The sample .pbix files will not work without these prerequites completed) 1. Install R En...
Smoothing Splines Showcase.pbix561 KB
ScriptInstallPackagesWithWorkaroundsSpline.R1 KB
General R Visualizations
Anonymous's avatar
Anonymous
Not applicable
8 years ago

Been looking at this visualization lately as I need to plot some datapoints and need to add regression lines. I'm plotting revenue/sales per day, and using the date as the category/legend. However, I need one line for each of the days, instead of one for all the data points.

How much work am I looking at doing smoething like this in R? 

boefraty's avatar
boefraty
Microsoft Employee
7 years ago

Hi, 

This is quite simple to achieve if you have basic expertise in R. 

I'd also recommend you to look at R Custom Visual  "Spline" it has regression lines 

You can use it as a starting point. 

 

  • Anonymous's avatar
    Anonymous
    Not applicable
    7 years ago

    I actually wrote a script that kinda fixed what I was trying to do, it's not pretty, but it works. Problem I got now is that I'm trying to make a custom visual out of it so I can get the highlighting features you used working. I assume it was plotly? I got multiple regression lines working, but plotly isn't playing along. Tried the RADACAD tutorial a few times, but I'm guessing my code is written in a way that it isn't a simple copy paste job anymore.

    library(ggplot2)
    p = qplot(1:10, (1:10)^3)
    g = ggplot(dataset, aes(x=Price, y=Production, color = Date))+
    geom_point() +
    theme(axis.text.x = element_text(size=14),
    axis.text.y = element_text(size=14),
    axis.title.x = element_text(size=16),
    axis.title.y = element_text(size=16),
    panel.background = element_rect(fill = "white",
    colour = "777777",
    size = 0.4, linetype = "solid"),
    panel.grid.major = element_line(size = 0.08, linetype = 'dashed',
    colour = "777777"),
    panel.grid.minor = element_line(size = 0.08, linetype = 'dashed',
    colour = "777777")) +
    theme(legend.position="bottom") +
    ylab("Production") +
    xlab("Price") +
    stat_smooth(method = "lm", formula = y ~ poly(x,2), size = 1, se = FALSE)
    g$respect = TRUE
    library(grid)
    grid.draw(g)

    Trying to get it working in this template.

    ############### Library Declarations ###############
    libraryRequireInstall("ggplot2");
    libraryRequireInstall("plotly")
    ####################################################

    ################### Actual code ####################
    g = qplot(Values$Data, data = Values, fill = Values$Type, main = Sys.time());
    ####################################################

    ############# Create and save widget ###############
    p = ggplotly(g);
    internalSaveWidget(p, 'out.html');




    https://community.powerbi.com/t5/Developer/Converting-power-bi-R-script-visual-to-custom-R-visual/m-p/498110#M15275

  • © 2026 Microsoft
  • Manage cookies
  • Privacy & cookies
  • Terms of use
  • Trademarks
Your Privacy Choices Consumer Health Privacy