library(highcharter)
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
library(dplyr) # group_by
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr) # gather
mydata <- data.frame(A=runif(1:10),
B=runif(1:10),
C=runif(1:10))
highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "MyGraph") %>%
hc_yAxis(title = list(text = "Weights")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = FALSE),
stacking = "normal",
enableMouseTracking = FALSE)
) %>%
hc_series(list(name="A",data=mydata$A),
list(name="B",data=mydata$B),
list(name="C",data=mydata$C))
mynewdata <- gather(mydata)
hchart(mynewdata, "column", hcaes(y = value, group = key)) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = FALSE),
stacking = "normal",
enableMouseTracking = FALSE)
)
mynewdata2 <- mynewdata %>%
# we change the key to name to have the label in the legend
group_by(name = key) %>%
# the data in this case is simple, is just .$value column
do(data = .$value)
highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "MyGraph") %>%
hc_yAxis(title = list(text = "Weights")) %>%
hc_plotOptions(column = list(
dataLabels = list(enabled = FALSE),
stacking = "normal",
enableMouseTracking = FALSE)
) %>%
hc_add_series_list(mynewdata2)
sessionInfo()
## R version 3.4.2 (2017-09-28)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
## [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Spain.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] tidyr_0.7.1 dplyr_0.7.4 highcharter_0.5.0.9999
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.13 compiler_3.4.2 plyr_1.8.4
## [4] bindr_0.1 tools_3.4.2 xts_0.10-0
## [7] digest_0.6.12 jsonlite_1.5 lubridate_1.6.0
## [10] evaluate_0.10.1 tibble_1.3.4 nlme_3.1-131
## [13] lattice_0.20-35 pkgconfig_2.0.1 rlang_0.1.2
## [16] psych_1.7.8 igraph_1.1.2 yaml_2.1.14
## [19] curl_3.0 parallel_3.4.2 bindrcpp_0.2
## [22] stringr_1.2.0 knitr_1.17 htmlwidgets_0.9
## [25] rprojroot_1.2 grid_3.4.2 data.table_1.10.4-1
## [28] glue_1.1.1 R6_2.2.2 foreign_0.8-69
## [31] rmarkdown_1.6 whisker_0.3-2 TTR_0.23-2
## [34] reshape2_1.4.2 purrr_0.2.3 magrittr_1.5
## [37] backports_1.1.1 htmltools_0.3.6 rlist_0.4.6.1
## [40] assertthat_0.2.0 quantmod_0.4-11 mnormt_1.5-5
## [43] stringi_1.1.5 broom_0.4.2 zoo_1.8-0