GithubHelp home page GithubHelp logo

hrbrmstr / metricsgraphics Goto Github PK

View Code? Open in Web Editor NEW
132.0 132.0 35.0 15.71 MB

:chart_with_upwards_trend: htmlwidget interface to the MetricsGraphics.js D3 chart library

Home Page: http://hrbrmstr.github.io/metricsgraphics/

License: Other

R 0.63% HTML 99.25% JavaScript 0.09% TeX 0.03%

metricsgraphics's Introduction

metricsgraphics

Build Status Project Status: Active - The project has reached a stable, usable state and is being actively developed. CRAN_Status_Badge downloads DOI

On CRAN: http://cran.r-project.org/web/packages/metricsgraphics/index.html

Vignette: http://cran.r-project.org/web/packages/metricsgraphics/vignettes/introductiontometricsgraphics.html

metricsgraphics is an 'htmlwidget' interface to the MetricsGraphics.js D3-based charting library.

Charts look best in a Boostrap page (unless you customize your own CSS).

You can see [core examples] (http://rpubs.com/hrbrmstr/53741) and fairly extended grid example on RPubs.

The following functions are implemented:

  • mjs_plot: Create a new metricsgraphics.js plot
  • mjs_line: metricsgraphics.js linechart "geom"
  • mjs_add_line: used to add additional columns for a multi-line chart
  • mjs_hist: Shortcut for plotting MetricsGraphics histograms
  • mjs_histogram: Plot Histograms with MetrisGraphics
  • mjs_add_legend: adds a legend to a line (or mult-line) chart
  • mjs_point: metricsgraphics.js scatterplot "geom"
  • mjs_bar: metricsgraphics.js bar chart "geom"
  • mjs_axis_x: Configure x axis ticks & limits
  • mjs_axis_y: Configure y axis ticks & limits
  • mjs_labs: Configure axis labels & plot description
  • mjs_add_baseline: Sets a baseline line/label
  • mjs_add_marker: Sets a marker line/label
  • mjs_grid: grid.arrange-like functionality for metricsgraphics charts
  • mjs_add_mouseover: provides support for MetricsGraphics custom rollovers
  • mjs_add_confidence_band: provides support for confidence bands
  • mjs_annotate_region: Region annotations for line charts [EXPERIMENTAL]
  • mjs_add_css_rule: Add a CSS rule to the rendered htmlwidget

Installation

# stable
install.packages("metricsgraphics")
# development
# devtools::install_github("hrbrmstr/metricsgraphics")

Usage

library(metricsgraphics)
library(RColorBrewer)

tmp <- data.frame(year=seq(1790, 1970, 10), uspop=as.numeric(uspop))

tmp %>%
  mjs_plot(x=year, y=uspop) %>%
  mjs_line() %>%
  mjs_add_marker(1850, "Something Wonderful") %>%
  mjs_add_baseline(150, "Something Awful")


tmp %>%
  mjs_plot(x=year, y=uspop, width=600) %>%
  mjs_line(area=TRUE)

tmp %>%
  mjs_plot(x=uspop, y=year, width=500, height=400) %>%
  mjs_bar() %>%
  mjs_axis_x(xax_format = 'plain')


mtcars %>%
  mjs_plot(x=wt, y=mpg, width=600, height=500) %>%
  mjs_point(color_accessor=carb, size_accessor=carb) %>%
  mjs_labs(x="Weight of Car", y="Miles per Gallon")


mtcars %>%
  mjs_plot(x=wt, y=mpg, width=600, height=500) %>%
  mjs_point(color_accessor=cyl,
            x_rug=TRUE, y_rug=TRUE,
            size_accessor=carb,
            size_range=c(5, 10),
            color_type="category",
            color_range=brewer.pal(n=11, name="RdBu")[c(1, 5, 11)]) %>%
  mjs_labs(x="Weight of Car", y="Miles per Gallon")


mtcars %>%
  mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
  mjs_point(least_squares=TRUE) %>%
  mjs_labs(x="Weight of Car", y="Miles per Gallon")


set.seed(1492)
dat <- data.frame(date=seq(as.Date("2014-01-01"),
                           as.Date("2014-01-31"),
                           by="1 day"),
                  value=rnorm(n=31, mean=0, sd=2))

dat %>%
  mjs_plot(x=date, y=value) %>%
  mjs_line() %>%
  mjs_axis_x(xax_format = "date")

# Custom rollovers

dat %>%
  mjs_plot(x=date, y=value) %>%
  mjs_line() %>%
  mjs_axis_x(xax_format = "date") %>%
  mjs_add_mouseover("function(d, i) {
                $('{{ID}} svg .mg-active-datapoint')
                    .text('custom text : ' + d.date + ' ' + i);
                 }")

# also works for scatterplots with a slight mod

set.seed(1492)
dat <- data.frame(value=rnorm(n=30, mean=5, sd=1),
                 value2=rnorm(n=30, mean=4, sd=1),
                 test = c(rep(c('test', 'test2'), 15)))
dat %>%
 mjs_plot(x = value, y = value2) %>%
 mjs_point() %>%
 mjs_add_mouseover("function(d, i) {
               $('{{ID}} svg .mg-active-datapoint')
                   .text('custom text : ' + d.point.test + ' ' + i);
                }")

set.seed(1492)
stocks <- data.frame(
  time = as.Date('2009-01-01') + 0:9,
  X = rnorm(10, 0, 1),
  Y = rnorm(10, 0, 2),
  Z = rnorm(10, 0, 4))

stocks %>%
  mjs_plot(x=time, y=X) %>%
  mjs_line() %>%
  mjs_axis_x(show=FALSE) %>%
  mjs_axis_y(show=FALSE)

stocks %>%
  mjs_plot(x=time, y=X) %>%
  mjs_line() %>%
  mjs_add_line(Y) %>%
  mjs_add_line(Z) %>%
  mjs_axis_x(xax_format="date")

mjs_plot(rnorm(10000)) %>%
  mjs_histogram(bins=30, bar_margin=1)

movies <- ggplot2movies::movies[sample(nrow(ggplot2movies::movies), 1000), ]

mjs_plot(movies$rating) %>% mjs_histogram()

mjs_plot(movies, rating) %>% 
  mjs_histogram() %>% 
  mjs_labs(x_label="Histogram of movie ratings", 
           y_label="Frequency")

mjs_plot(movies$rating) %>% mjs_histogram(bins=30)

mjs_plot(runif(10000)) %>% 
  mjs_labs(x_label="runif(10000)") %>%
  mjs_histogram()


mjs_plot(rbeta(10000, 2, 5)) %>%
  mjs_labs(x_label="rbeta(10000, 2, 3)") %>%
  mjs_histogram(bins=100) %>% 
  mjs_axis_y(extended_ticks=TRUE)

bimod <- c(rnorm(1000, 0, 1), rnorm(1000, 3, 1))
mjs_plot(bimod) %>% mjs_histogram() 
mjs_plot(bimod) %>% mjs_histogram(bins=30) 

bimod %>% mjs_hist(30)

library(shiny)
library(metricsgraphics)

ui = shinyUI(fluidPage(
  h3("MetricsGraphics Example", style="text-align:center"),
  metricsgraphicsOutput('mjs1'),
  br(),
  metricsgraphicsOutput('mjs2')
))

server = function(input, output) {

  mtcars %>%
    mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
    mjs_point(color_accessor=carb, size_accessor=carb) %>%
    mjs_labs(x="Weight of Car", y="Miles per Gallon") -> m1

  set.seed(1492)
  stocks <- data.frame(
    time = as.Date('2009-01-01') + 0:9,
    X = rnorm(10, 0, 1),
    Y = rnorm(10, 0, 2),
    Z = rnorm(10, 0, 4))

  stocks %>%
    mjs_plot(x=time, y=X) %>%
    mjs_line() %>%
    mjs_add_line(Y) %>%
    mjs_add_line(Z) %>%
    mjs_axis_x(xax_format="date") %>%
    mjs_add_legend(legend=c("X", "Y", "Z")) -> m2

  output$mjs1 <- renderMetricsgraphics(m1)

  output$mjs2 <- renderMetricsgraphics(m2)

}

shinyApp(ui = ui, server = server)

There's another example provided by https://github.com/DocOfi which can be viewed at http://rpubs.com/DocOfi/352947. The Rmd file that created the example can be found at https://github.com/DocOfi/datasciencecoursera/tree/master/Exploratory_Data_Analysis/MetricsGraphics

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

metricsgraphics's People

Contributors

arfon avatar docofi avatar earino avatar hrbrmstr avatar jjallaire avatar jrowen avatar paul-james avatar yihui avatar yutannihilation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

metricsgraphics's Issues

IE cannot render charts with jquery 2.1

IE users can't see the graph generated by metricsgraphics at all. In case you are a non-Windows user, here is a screenshot I took with my IE11:

ie

Meanwhile, the official site [http://metricsgraphicsjs.org/] works perfectly fine with IE. One of the differences is the version of jquery; They uses 1.11.1 and we use 2.1.X in this metricsgraphics package.

I did bower install jquery#1.11.1 in metricsgraphics as an experiment, and then I saw charts were drawn correctly. It seems better to downgrade jquery, if you care about IE :)

metricsgraphics_html returned an object of class `list` instead of a `shiny.tag`

When I run the following code from the documentation:

data.frame(year=seq(1790, 1970, 10), uspop=as.numeric(uspop)) %>%
  mjs_plot(x=year, y=uspop) %>%
  mjs_line()

I get the following message:

Warning message:
In widget_html(name = class(x)[1], package = attr(x, "package"), :
metricsgraphics_html returned an object of class list instead of a shiny.tag.

The plot is produced in RStudio, but does not show up in an Rmd file when it is rendered.
In ideas as to how to get this working again in an Rmd file?

Issue with plotting time series after enhancement

The data column for time has been formatted to date before plotting by:
final$SAMPLED_DATE <- as.Date(final$SAMPLED_DATE,"%Y-%m-%d")

However, when trying to plot within Shiny, I receive the following error:
Error in as.Date.default(mjs$x$data[, as.character(mjs$x$x_accessor)], : do not know how to convert 'mjs$x$data[, as.character(mjs$x$x_accessor)]' to class โ€œDateโ€

Plotting a different column which is numeric works, it's just plotting with a date that doesn't work
My code for the server side is:
final %>% mjs_plot(x=SAMPLED_DATE, y=AROMATICS) %>% mjs_point()%>% mjs_labs(x="Date", y="Density")%>% mjs_axis_x(xax_format="date")-> m1 output$mjs1 <- renderMetricsgraphics(m1)

Any ideas why this error is popping up?

unable to set x axis limits for histogram

I have a dataset that has a range of 30 to 99 and I would like to force the x axis to run from 0 to 100

However, the code below produces a chart that starts at ~30 in shiny / shinydashboard

Is there something I'm missing?

Thanks

output$histo_demo<-renderMetricsgraphics({

  dfz<-data.frame(x=c(30,30,90,96,99,45))

  mjs_plot(dfz, x) %>%
    mjs_histogram(bins=20) %>%
    mjs_labs(y_label="Count ") %>%  
    mjs_axis_x(min_x=0, max_x=100)
})

session info:

R version 3.1.2 (2014-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C           
 [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] tcltk     stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] uuid_0.1-1            DT_0.0.39             xts_0.9-7             zoo_1.7-12            dygraphs_0.4.3        magrittr_1.5          scales_0.2.4          reshape2_1.4         
 [9] ggplot2_1.0.0         plyr_1.8.1            rjson_0.2.15          metricsgraphics_0.8.5 htmlwidgets_0.3.3     rCharts_0.4.5         RJDBC_0.2-4           rJava_0.9-6          
[17] lubridate_1.3.3       sqldf_0.4-10          RSQLite_1.0.0         DBI_0.3.1             gsubfn_0.6-6          proto_0.3-10          shinyBS_0.61          shinydashboard_0.2.3 
[25] shiny_0.11.1.9004    

loaded via a namespace (and not attached):
 [1] MASS_7.3-35      R6_2.0.1         RJSONIO_1.3-0    Rcpp_0.11.3      chron_2.3-45     colorspace_1.2-4 digest_0.6.4     grid_3.1.2       gtable_0.1.2     htmltools_0.2.6 
[11] httpuv_1.3.2     lattice_0.20-29  memoise_0.2.1    mime_0.3         munsell_0.4.2    stringr_0.6.2    tools_3.1.2      whisker_0.3-2    xtable_1.7-4     yaml_2.1.13     

mjs_add_mouseover works in RStudio, but I cannot get it to work with shiny.

Rather than show custom text on points of a scatterplot in shiny, it appears to be showing default text. If I run that same core chunk of code directly from RStudio the plot shows up in the plot pane and the points all have the expected custom mouse-over text.

Thoughts?

library(shiny)
library(metricsgraphics)

server <- function(input, output) {
  output$distPlot <- renderMetricsgraphics({
    dat <- data.frame(value=rnorm(n=30, mean=5, sd=1),
                      value2=rnorm(n=30, mean=4, sd=1),
                      test = c(rep(c('test', 'test2'), 15)))

    dat %>%
      mjs_plot(x = value, y = value2) %>%
      mjs_point() %>%
      mjs_add_mouseover("function(d, i) {
                            $('{{ID}} svg .mg-active-datapoint')
                            .text('custom text : ' + d.point.test + ' ' + i);
                         }")
  })
}

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
    ),
    mainPanel(metricsgraphicsOutput("distPlot"))
  )
)

shinyApp(ui = ui, server = server)

System info:

R version 3.2.1 (2015-06-18)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] metricsgraphics_0.8.5 shiny_0.12.1         

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.5 magrittr_1.5    R6_2.1.0        htmltools_0.2.6 tools_3.2.1    
 [6] yaml_2.1.13     Rcpp_0.12.0     jsonlite_0.9.16 digest_0.6.8    xtable_1.7-4   
[11] httpuv_1.3.2    mime_0.3       

RStudio 0.99.467 says packages are up to date.

gh-pages for this package

Found the blog post introducing metricsgraphics (http://rud.is/b/2015/01/08/new-r-package-metricsgraphics/) to be excellent. Perhaps this could be combined with the existing README.md examples to create a gh-pages site for the repo. I'm interested in this primarily because it would be great to link to metricsgraphics from the htmlwidgets showcase page (http://www.htmlwidgets.org/showcase_leaflet.html) and it would be so much nicer for it to be to a documentation page rather than the raw github repo.

Error when plotting Histogram

Hello,
I have been trying to plot a histogram, but every time I do so, I get an error.

The code I use is:

mjs_plot(rnorm(10000)) %>%
mjs_histogram()

And the error I get it is:

Error in data[, x] : incorrect number of dimensions

Adjust Chart Padding in Shiny

I'm using this library to create scatter charts in a Shiny app. Things are working out pretty well so far, apart from one thing. That is the padding around the chart. Please see the image below.

relativestrengthscatter

On the right is a table from the DT package, which fits nicely in the tabBox with minimal borders. However, on the left, the metricsgraphics chart has considerable padding around the X and Y axis, resulting in quite a lot of wasted space. The right hand side of the chart appears to be fine, with minimal padding.

My chart output code is the following (apologies this is not a fully reproducable, self contained Shiny example):

  rsScatter %>%
    mjs_plot(x=POWV, y=RSP) %>%
    mjs_point(color_accessor=POWr, 
              size_accessor=BFOdds, 
              least_squares=TRUE,
              size_range=c(3, 50),
              color_type="category",
              color_range=rev(brewer.pal(n=9, name="Greens"))) %>%
    mjs_labs(x="POW V%", y="RSP") %>%
    mjs_add_baseline(1.25, "RSP 1.25") %>%
    mjs_add_mouseover("function(d, i) {
               $('#rsp svg .mg-active-datapoint')
                   .text(d.point.COURSE + ' ' + d.point.TIME + ': ' + d.point.HORSE + ' | POWr: ' + d.point.POWr + ' | POW: ' + d.point.POW + ' | POW V: ' + d.point.POWV + '%' + ' | RSP: ' + d.point.RSP +' | BF Odds: ' + d.point.BFOdds);
                }") -> rsp

Issue with multiple mjs graphs in shiny

library(shiny)
library(metricsgraphics)

ui = shinyUI(fluidPage(
  h3("MetricsGraphics Example", style="text-align:center"),
  metricsgraphicsOutput('mjs1'),
  metricsgraphicsOutput('mjs2')
))

server = function(input, output) {
  output$mjs1 <- renderMetricsgraphics(
    mtcars %>%
      mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
      mjs_point(color_accessor=carb, size_accessor=carb) %>%
      mjs_labs(x="Weight of Car", y="Miles per Gallon")
  ),
  output$mjs2 <- renderMetricsgraphics(
    set.seed(1492)
    stocks <- data.frame(
      time = as.Date('2009-01-01') + 0:9,
      X = rnorm(10, 0, 1),
      Y = rnorm(10, 0, 2),
      Z = rnorm(10, 0, 4))
    stocks %>%
      mjs_plot(x=time, y=X) %>%
      mjs_line() %>%
      mjs_add_line(Y) %>%
      mjs_add_line(Z) %>%
      mjs_axis_x(xax_format="date") %>%
      mjs_add_legend(legend=c("X", "Y", "Z"))
  )
}

shinyApp(ui = ui, server = server)

ends up casing:

Listening on http://127.0.0.1:4326
Warning in func() :
Ignoring explicitly provided widget ID "mjs-e4befd1929ef888b07e1654d3e2432"; Shiny doesn't use them

and not displaying the second graphic.

mjs_add_line does not display X values correctly with mjs_axis_x(format="plain")

Hi,

When moving the cursor over the line I get the wrong data displayed in the top right corner. For now it seems to me that the problem is only encountered with format="plain".

Example code:

h <- data.frame(a = c(4:8), b = seq(2000, 6000, 1000), d = rep(4000, 5))

h %>%
  mjs_plot(x = a,
           y = b) %>%
  mjs_add_line(d) %>%
  mjs_axis_x(xax_format = "plain")

The problem can be tracked on printscreen: both lines are named 'a' and contain undefined as x-values.

default

With X variable of class Date there seems to be no problem.

str() of the same data, but now a contains dates

'data.frame':	5 obs. of  3 variables:
 $ a: Date, format: "2010-05-31" "2011-06-30" "2012-11-30" "2013-01-31" ...
 $ b: num  2000 3000 4000 5000 6000
 $ d: num  4000 4000 4000 4000 4000

Works fine:

default

mjs_add_mouseover: Doesn't work with mjs_point

Hi,

I am testing out the mjs_add_mouseover and was using the test example as an template. I've noticed that it adds custom text for mjs_line(), but doesn't seem to work with the mjs_point()? For example, considering the following data:

dat <- data.frame(value=rnorm(n=30, mean=5, sd=1),
                  value2=rnorm(n=30, mean=4, sd=1),
                  test = c(rep(c('test', 'test2'), 15)))

dat %>%
  mjs_plot(x = value, y = value2) %>%
  mjs_line() %>%
  mjs_add_mouseover("function(d, i) {
                $('{{ID}} svg .mg-active-datapoint')
                    .text('custom text : ' + d.test + ' ' + i);
                 }")

Custom text is added with the d.test, but if I do the following:

dat %>%
  mjs_plot(x = value, y = value2) %>%
  mjs_point() %>%
  mjs_add_mouseover("function(d, i) {
                $('{{ID}} svg .mg-active-datapoint')
                    .text('custom text : ' + d.test + ' ' + i);
                 }")

I get an undefined for the custom test? Am I missing something here?

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.4.1         data.table_1.9.4    metricsgraphics_0.7 htmltools_0.2.6     htmlwidgets_0.3.2   vimcom_1.0-0        setwidth_1.0-3      colorout_1.1-0

loaded via a namespace (and not attached):
 [1] assertthat_0.1  chron_2.3-45    DBI_0.3.1       digest_0.6.8    lazyeval_0.1.10 magrittr_1.5    parallel_3.1.2  plyr_1.8.1      Rcpp_0.11.4     reshape2_1.4.1  RJSONIO_1.3-0   stringr_0.6.2   tools_3.1.2     yaml_2.1.13

Dealing with explicitly provided widget id warning when using shiny

I've built a shiny application that uses metricsgraphics to create histogram. When running the application I get the following error message:

Warning in output$histPlot(...) : Ignoring explicitly provided widget ID "mjs-acd1c2bc860bf1a81780a7603d6f7b"; Shiny doesn't use them

My app can be run with the following command:

shiny::runGitHub(repo = 'mihiriyer/mental')

My code is located here:
https://github.com/mihiriyer/mental/blob/master/app.R

The app seems to work fine and so should I even be worried since it is just a warning? Should I just suppress the message and move on?

Linked charts

I like the linked charts and want to link them on a 3rd variable, but have not found a way to do so.

Assume you have the mtcars dataset, x-axis = mpg and you have 2 scatterplots, with y-axis disp and hp respectively. Then the rollover value that I would like to see is the car model, not just x =mpg and y = disp or y = hp.

Is there a possibility to make this link in metricsgraphics?

mjs_add_marker not working with mjs_histogram

Hi there,

It seems that mjs_add_marker is not working in conjunction with mjs_histogram.

mjs_plot(full_summary[(var_id=="Tot"),.(sum_val)], x=sum_val, decimals = 0, width=300, height=300) %>% mjs_histogram(bar_margin=2) %>% mjs_add_marker(x_value=average_val, label="Av. Val") %>% mjs_labs(x_label="Total value")

It will plot the histogram, but the vertical marker is not plotted.

Version: metricsgraphics 0.9.0
R-Version: 3.2.3

Linked Charts with Multiple Lines

Linked Charts with multiple lines seem to not be working.

I tried replicating the example found at the bottom of http://hrbrmstr.github.io/metricsgraphics/ to no success.

The only way to make it work is if I change the variable name of X to value and only use one line. Even then I lose the actual value and encounter the same issue as #51.

The examples for other types of graphs still work, as in here and here.

My session info:

R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
metricsgraphics_0.9.1

mjs_axis_x(xax_format = "date") masks y mouseover

Hi,

When formatting the x-axis as a date, the y mouseover is no longer displayed. Below is an example showing this.

Dataset:

> head(thd)
        date hits
1 2012-05-06   68
2 2012-05-13   69
3 2012-05-20   70
4 2012-05-27   68
5 2012-06-03   67
6 2012-06-10   67
> str(thd)
'data.frame':	260 obs. of  2 variables:
 $ date: Date, format: "2012-05-06" "2012-05-13" "2012-05-20" ...
 $ hits: int  68 69 70 68 67 67 67 68 69 66 ...

Graph, without x-axis formatted as date:

> thd %>% mjs_plot(x = date, y = hits)%>%
+     mjs_line() %>%
+     mjs_labs(x = "Date", y = "Search Hits")

image

Graph, with x-axis formatted as date:

> thd %>% mjs_plot(x = date, y = hits)%>%
+     mjs_line() %>%
+     mjs_axis_x(xax_format = "date") %>%
+     mjs_labs(x = "Date", y = "Search Hits") 

image

As you can see, the y-axis mouseover (hits) is no longer visible once the x-axis is formatted as a date.

R version 3.4.0
metricsgraphics_0.9.0

Warning in run(timeoutMs)

Hi,

Running this :

library(shiny)
library(metricsgraphics)

ui = shinyUI(fluidPage(
  h3("MetricsGraphics Example", style="text-align:center"),
  metricsgraphicsOutput('mjs1'),
  br(),
  metricsgraphicsOutput('mjs2')
))

server = function(input, output) {

  mtcars %>%
    mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
    mjs_point(color_accessor=carb, size_accessor=carb) %>%
    mjs_labs(x="Weight of Car", y="Miles per Gallon") -> m1

  set.seed(1492)
  stocks <- data.frame(
    time = as.Date('2009-01-01') + 0:9,
    X = rnorm(10, 0, 1),
    Y = rnorm(10, 0, 2),
    Z = rnorm(10, 0, 4))

  stocks %>%
    mjs_plot(x=time, y=X) %>%
    mjs_line() %>%
    mjs_add_line(Y) %>%
    mjs_add_line(Z) %>%
    mjs_axis_x(xax_format="date") %>%
    mjs_add_legend(legend=c("X", "Y", "Z")) -> m2

  output$mjs1 <- renderMetricsgraphics(m1)

  output$mjs2 <- renderMetricsgraphics(m2)

}

shinyApp(ui = ui, server = server)

... i have the following error :

Warning in run(timeoutMs) :
Ignoring explicitly provided widget ID "mjs-f1fc5c26a7aa7c051153d71f014972"; Shiny doesn't use them
Warning in run(timeoutMs) :
Ignoring explicitly provided widget ID "mjs-b1f2d1491b106d35e2225e83397445"; Shiny doesn't use them

After one hour looking for the solution, I did not find it.
Do someone have any tips to fix it?

Thanks

Use with Reactive Data in Shiny

I am new to metricsgrphics, but it looks like a useful tool. I am trying to integrate a histogram into a shiny dashboard.

The following works, but the data is static:

output$hist <- renderMetricsgraphics(

dataset %>%
mjs_plot(var1, width=300, height=300) %>%
mjs_histogram() %>%
mjs_labs(x_label=sprintf("x label"))
)

The following does not work:

output$hist <- renderMetricsgraphics(

zipsInBounds() %>%
mjs_plot(var1, width=300, height=300) %>%
mjs_histogram() %>%
mjs_labs(x_label=sprintf("x label"))
)

Thanks for any guidance/updates.

Doesn't work with shiny navbarMenu page.

Hi, for some reasons if you put metricsgraphics on navbarMenu page, you can't access tabs.
Here is a small example.

library(shiny)
library(metricsgraphics)

ui = shinyUI(navbarPage("Navbar!",
                        tabPanel("Home", h3("MetricsGraphics Example")),
                        navbarMenu("Plots",
                                   tabPanel("Plot1",
                                        metricsgraphicsOutput('mjs1')
                                    ),
                                    tabPanel("Plot2",
                                        metricsgraphicsOutput('mjs2')
                                    )
                        )
))

server = function(input, output) {

    mtcars %>%
        mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
        mjs_point(color_accessor=carb, size_accessor=carb) %>%
        mjs_labs(x="Weight of Car", y="Miles per Gallon") -> m1

    set.seed(1492)
    stocks <- data.frame(
        time = as.Date('2009-01-01') + 0:9,
        X = rnorm(10, 0, 1),
        Y = rnorm(10, 0, 2),
        Z = rnorm(10, 0, 4))

    stocks %>%
        mjs_plot(x=time, y=X) %>%
        mjs_line() %>%
        mjs_add_line(Y) %>%
        mjs_add_line(Z) %>%
        mjs_axis_x(xax_format="date") %>%
        mjs_add_legend(legend=c("X", "Y", "Z")) -> m2

    output$mjs1 <- renderMetricsgraphics(m1)

    output$mjs2 <- renderMetricsgraphics(m2)

}

shinyApp(ui = ui, server = server)

multiline - plots not animated and no legend

I am trying to plot a multiline graph. Facing two issues:

  1. No Animation
  2. Legend not coming up

Below is my code:
plotForecast <- data.frame(hourIndex=1:24,testHourP=1:24,d1P=25:48,enerDataP=49:72)

plotForecast %>%
mjs_plot(x=hourIndex, y=testHourP) %>%
mjs_line() %>%
mjs_add_line(d1P) %>%
mjs_add_line(enerDataP) %>%
mjs_add_legend(legend=c("X", "Y", "Z"))

EDIT:
The program seems to be missing mjs_axis_x() function. Without using this function, multi-line plots do not animate.

add support for time series

As you can probably tell, I am very interested in this. If ok, can we add this issue to track progress on the quote from Readme.md?

does not really take advantage of metricsgraphics' best feature - time series charts

@jjallaire might have some ideas here and think it would be very good to leverage the infrastructure with xts provided by rstudio/dygraphs lines especially given some of the complexities already discovered with things such as time zones rstudio/dygraphs#16 and date formats rstudio/dygraphs#21 .

Happy to close if you think not helpful.

cannot sync plots

In Shiny, I can play with your examples and it seems that you can sync plots if they share data.

(side note, Shiny spits out the following error on every plot:
Warning in func() :
Ignoring explicitly provided widget ID "mjs-fb344f7633c8c494b972c9da68b35c"; Shiny doesn't use them)

Should I be able to link plots A and B if their X-axis share at least SOME of the same values?

Plots render incorrectly

OS: Windows
R Version: 3.2.1

YTD.cost.per.content.set.not.blank %>%
  mjs_plot(x=Content.Set, y=Cost) %>%
  mjs_point(color_accessor=Cost, size_accessor=Cost) %>%
  mjs_labs(x="Content Set", y="Cost")

rplot

Allow explicit variable names in mjs_plot

Consider the following:

I have a data.frame and I want to use one variable as the y axis and every other column in the data.frame as the x-axis for a grid of plots based on said data.frame.

I was hoping for something like this to work:

plots <- lapply(names(generalstats[-1]), function(col){
            generalstats %>%
            mjs_plot(x=col, y=player) %>%
              mjs_bar()
          })
mjs_grid(plots, nrow=13, ncol=4)

With generalstats looking something like this:

> head(generalstats)
      player climbOneCm damageDealt mobKills boatOneCm damageTaken   jump leaveGame deaths fishCaught
Jemus42    2415375      802543    17040   1558130      112780  87755       295     37         18
BenemitC     130339      135208     8748     76694      127204  15806        55      4         24
L3viathan    2832879     1083695    37449    131341     1188400 355807       788     76        117
Fenhl    6928955     1849623    95270   2983399      993163 328840      1386     85       3324
Farthen    1295570      222548     8831         0      143204 126832       267     99         10
viirus42      44785         633        5         0       18808    805         2      8          0

If the values for x and y were not supposed to be barebone column names, this would work.
Another way would be for mjs_plot to accept explicit vectors of data for each x and y, without even having to supply a data.frame in the first place.

remove .bowerrc if submitting to CRAN

Maybe a little premature for a CRAN submission discussion, but with DiagrammeR today, the CRAN submission was refused for a couple of reasons. Removing or really just adding to git ignore .bowerrc is relatively simple and harmless.

How to render?

As someone new to markdown it wasn't clear what render() markdown call to use to (and related markdown usage) to generate portable html files for sharing. The output of metric graphics was as expected when generated from within R, but the moment I went to render I had success but ugly graphics. I think I used render inappropriately and the metricsgraphics doesn't have an example to steer me appropriately in that usecase.

add plot title and description

It would be helpful if mjs_plot carried a couple additional options from the native MetricsGraphics.js utiility, including title and description. Thank you for providing this excellent capability.

Adjust Chart Font Sizes in Shiny

I'm struggling to understand how to adjust chart font sizes for a metricsgraphics chart in Shiny. I've read the documentation, examined the functions and tried StackOverflow without finding a solution for this one.

Below are two examples of the same chart, generated with the same code.

In RStudio:

rsf-rstudio

In the Shiny app:

rsscatter

As you can see the axis labels, marker and baseline font sizes are different. The ones in RStudio are OK, the ones in Shiny a bit small.

I've tried adjusting chart dimensions and padding, but neither made a difference.

Example code:

  rsScatter %>%
    mjs_plot(x=FBRV, y=RSF, left = 20, bottom = 20, top = 10) %>%
    mjs_point(color_accessor=FBRr, 
              size_accessor=BFOdds, 
              least_squares=TRUE,
              size_range=c(3, 50),
              color_type="category",
              point_size=1,
              color_range=rev(brewer.pal(n=9, name="Greens"))) %>%
    mjs_labs(x="FBR V%", y="RSF") %>%
    mjs_add_baseline(1.25, "RSF 1.25") %>%
    mjs_add_marker(0, "FBR V: 0%") %>%
    mjs_add_mouseover("function(d, i) {
               $('#rsf svg .mg-active-datapoint')
                   .text(d.point.COURSE + ' ' + d.point.TIME + ': ' + d.point.HORSE + ' | FBRr: ' + d.point.FBRr + ' | FBR: ' + d.point.FBR + ' | FBR V: ' + d.point.FBRV + '%' + ' | RSF: ' + d.point.RSF +' | BF Odds: ' + d.point.BFOdds);
                }")

track jquery removal and remove from yaml when ready

I thought it might be good to set this up as a reminder to track metricsgraphics/metrics-graphics#132. This might not be all that significant, since jquery will often probably be required from some other component, but I believe it will be a good best practice to minimize the size of htmlwidgets dependencies especially once users get accustomed to composing with multiple widgets.

Since I did not see any jquery in the widget js I think it simply means removing the dependency in yaml.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.