Skip to content

Commit

Permalink
min all plugings and close #262
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkunst committed Feb 9, 2017
1 parent 3190ba5 commit 6e73453
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 3,576 deletions.
47 changes: 47 additions & 0 deletions R/highcharts-regression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
library(ggplot2)
library(highcharter)
library(dplyr)

data(mpg, diamonds, package = "ggplot2")

hchart(mpg, "point", hcaes(displ, hwy, group = drv), regression = TRUE) %>%
hc_colors(c("#d35400", "#2980b9", "#2ecc71"))


library(quantmod)
x <- getSymbols("GOOG", auto.assign=FALSE)

hchart(x, regression = TRUE,
regressionSettings = list(type = "loess", loessSmooth = 30))

highchart() %>%
hc_add_series(data = list_parse2(cars), type = "scatter", regression = TRUE,
regressionSettings = list(type = "loess", loessSmooth = 2))

hchart(cars, "point", hcaes(speed), regression = TRUE,
regressionSettings = list(type = "loess", loessSmooth = 0.5))


ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth()


lm(hwy ~ displ, data = mpg)

hchart(mpg, "point", hcaes(displ, hwy), regression = TRUE,
regressionSettings = list(type = "polynomial", order = 5, hideInLegend = TRUE))


d <- sample_n(diamonds, 500)
d
hchart(d, "point", hcaes(carat, price, group = cut),
color = "transparent",
regression = TRUE,
regressionSettings = list(type = "polynomial", order = 5, hideInLegend = TRUE))



ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(method = "lm")
3 changes: 2 additions & 1 deletion dev/download-highcharts-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ files <- c(
"https://raw.githubusercontent.com/highcharts/draggable-legend/master/draggable-legend.js",
"https://raw.githubusercontent.com/highcharts/export-csv/master/export-csv.js",
"https://raw.githubusercontent.com/rudovjan/highcharts-tooltip-delay/master/tooltip-delay.js",
"https://raw.githubusercontent.com/blacklabel/grouped_categories/master/grouped-categories.js"
"https://raw.githubusercontent.com/blacklabel/grouped_categories/master/grouped-categories.js",
"https://raw.githubusercontent.com/streamlinesocial/highcharts-regression/master/highcharts-regression.js"
)

map2(
Expand Down
1 change: 1 addition & 0 deletions inst/htmlwidgets/highchart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
# - modules/accessibility.js
# - modules/canvas-tools.js
# - modules/boost.js
- plugins/highcharts-regression.js
- plugins/draggable-points.js
- plugins/export-csv.js
- plugins/grouped-categories.js
Expand Down
Loading

3 comments on commit 6e73453

@Elizemiku
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I downloaded these latest package updates today and I try use this function :
hchart(cars, "point", hcaes(speed), regression = TRUE, regressionSettings = list(type = "loess", loessSmooth = 0.5))
and the graph does not appear, just a message: no data to display.

Could this be a problem with my Rstudio?
Thanks, now your graphics with regression interactive are amazing!

@jbkunst
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Elizemiku !

First of all, hchart(cars, "point", hcaes(speed)) will not work because highcharts doesnt know how interpret point without a y component, and with highcharter I dont make any guess to try to chart the data when only the x aesthetic is given.

Secondly, as you know I've using the highchart-regression plugin and according with my test "loess" only work for highstocks. But now I'm working on something like this:

highchart() %>% 
  hc_add_series(cars, "point", hcaes(speed, dist)) %>% 
  hc_add_series(lm(dist ~ speed, data = cars), name = "Regression")

image

loessmodel <- loess(dist ~ speed, data = cars, span = 0.5)

highchart() %>% 
  hc_add_series(cars, "point", hcaes(speed, dist), name = "Some points") %>% 
  hc_add_series(loessmodel, name = "Loess")

image

Maybe is longer than add an option (like regression = TRUE) but I think we have more control about the input to the higcharts because I really don't know how the pluging works and what calculations do.

Finally, you can still using the regression-plugin, but you need to add the pluging manually (via hc_add_dependency) due I want to keep the deafult highcharts() the light as possible (and every plugin make the file size bigger):

hchart(mtcars, "point", hcaes(disp, hp, group = paste("am", am)), regression = TRUE) %>%
  hc_add_dependency("plugins/highcharts-regression.js")

image

Thanks to you! You're who bring the regression to the highcharter πŸ˜‰

@Elizemiku
Copy link

@Elizemiku Elizemiku commented on 6e73453 Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jbkunst!
Oh! I understand now. I'm flattered that I helped ^-^
The way you did it was great. I always will use highcharter to my graphs with regression.

Please sign in to comment.