skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Office 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
    • Getting started
      • Overview
      • Online workshops
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • R Script Showcase
    • Data Smoothing with Splines

    Data Smoothing with Splines

    08-15-2016 09:37 AM - last edited 11-16-2016 01:29 AM

    Microsoft Sharon
    Microsoft
    48623 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Sharon
    Microsoft Sharon
    Microsoft
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    Data Smoothing with Splines

    ‎08-15-2016 09:37 AM

    approval rating.JPG

    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 Engine

    Power BI Desktop does not include, deploy or install the R engine. To run R scripts in Power BI Desktop, you must separately installR on your local computer. You can download and install R for free from many locations, including the Revolution Open download page, and the CRAN Repository.

     

    2. Install the required R packages.

    Download the R script attached to this message and run it to install all required packages on your local machine. 

     

    Required R packages:

    graphins, spline, scales


    Tested on:

    CRAN 3.3.1, MRO 3.3.0, powerbi.com

     

    Legal Disclaimers:

    Terms of Service and Third Party Programs.

     

    Preview file
    8 KB
    Smoothing Splines Showcase.pbix
    ScriptInstallPackagesWithWorkaroundsSpline.R
    Labels:
    • Labels:
    • General R Visualizations
    Message 1 of 9
    48,623 Views
    18
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    andymc123
    andymc123 Advocate III
    Advocate III
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎09-19-2019 08:27 AM

    I have R installed, but I am a rookie.  I was able to install all of the necessary packages so that the sample .pbix file provided here loads and works just fine for me.  When I try to add the spline visual to my own .pbix file it doesn't want to accept measures in the X and Y axis.  Message on the visual simply states "Need numeric X and Y variables".  They are numeric, the Data Type is "Decimal Number", but formatted as "Percentage".  Why wouldn't I be able to use measures?  The data I have works just fine with the built in Power BI "scatter chart".  What I really want is the line so that I can keep a National Average line on the visual and cross-highlight by districts to see the distance from a National Average.

     

    Very cool visual, I hope that I can get it working.

    Message 9 of 9
    28,044 Views
    0
    Reply
    ropebender
    ropebender
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎04-24-2019 09:24 AM

    I have a couple of visuals I want to use from R, but when I try to load this visual (and others) I am having issues trying to install the needed libraries  I uninstalled the current version or R (3.5.1) and installed the version given in most all the visualizations in this section (3.3.1), but still I can't load most of the required libraries.

     

    You say the visualization you require requires 

     

    Required R packages:

    graphins, spline, scales

     

    I can load scales, spline is not available for 3.3.1, but I installed splines2 which was available and I assume is similar enough thet I can make it work.  However I don't know what to do with graphins.  I can't find anything similar at CRAN, CRAN2, R-Forge, or rforge.net.  Is there another repository that I should be using?

     

    Thanks!  

    Message 7 of 9
    33,694 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to ropebender
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-21-2019 06:41 AM

    hello!

     

    is there a newer version of this? the script to install dependencies is no longer working.

    Message 8 of 9
    29,348 Views
    0
    Reply
    jdt008
    jdt008 Helper II
    Helper II
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-06-2017 09:16 AM

    We love this visual.  How should the script read if my dates are formatted as mm/dd/yyyy?

     

    Thanks

    Message 2 of 9
    44,997 Views
    0
    Reply
    boefraty
    Microsoft boefraty
    Microsoft
    In response to jdt008
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎04-22-2017 11:56 PM

    Hi, sorry for the delay in reply. 

    The X column is of type "numeric". You can convert "date" type to "numeric" in Power Query. Next you need to take care of X-axis ticks labels, to be formatted as you want. 

    I did something similar in 
    https://community.powerbi.com/t5/R-Script-Showcase/ARIMA-forecasting/m-p/124237

    Please have a look at the R code. If you still have trouble with it, you are welcome to send me the PBIX 

     

    Message 3 of 9
    44,562 Views
    0
    Reply
    KristianA
    KristianA Advocate II
    Advocate II
    In response to boefraty
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-10-2018 05:59 AM

    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? 

    Message 4 of 9
    38,886 Views
    0
    Reply
    boefraty
    Microsoft boefraty
    Microsoft
    In response to KristianA
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-27-2018 03:53 AM

    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. 

     

    Message 5 of 9
    38,712 Views
    0
    Reply
    KristianA
    KristianA Advocate II
    Advocate II
    In response to boefraty
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-27-2018 05:55 AM

    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-...

    Message 6 of 9
    38,702 Views
    0
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2022 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks