Data Smoothing with Splines
08-15-2016 09:37 AM - last edited 11-16-2016 01:29 AM
Data Smoothing with Splines
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-15-2016
09:37 AM
- last edited on
11-16-2016
01:29 AM
by
boefraty
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.
Re: Data Smoothing with Splines
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- 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
Re: Data Smoothing with Splines
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- 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
Re: Data Smoothing with Splines
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- 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?
Re: Data Smoothing with Splines
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- 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.
Re: Data Smoothing with Splines
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- 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');