GithubHelp home page GithubHelp logo

Comments (7)

pandurang-kolekar avatar pandurang-kolekar commented on June 12, 2024

I also have the same issue. It would be great if mjs_plot() could process the r variables instead of fixed bare names of the variables.

from metricsgraphics.

hrbrmstr avatar hrbrmstr commented on June 12, 2024

I just pushed 0.7.5 which enables accessor parameters in functions to be either bare or quoted (i.e. modified mjs_plot, mjs_point&mjs_add_line`). I made a few local tests and it seems to work but if y'all could give it a whirl and let me know that'd be cool.

from metricsgraphics.

jrowen avatar jrowen commented on June 12, 2024

I would also agree with the earlier comments and would find it very useful if the code chunk below worked (this is similar to ggplot2::aes_string). I can confirm that mjs_plot(x = "wt", y = "mpg") now works.

x = "wt"
y = "mpg"

mtcars %>%
  mjs_plot(x=x, y=y) %>%
  mjs_point(color_accessor=carb, size_accessor=carb) %>%
  mjs_labs(x="Weight of Car", y="Miles per Gallon")

from metricsgraphics.

pandurang-kolekar avatar pandurang-kolekar commented on June 12, 2024

@hrbrmstr I also confirmed that the 0.7.5 version works fine with quoted strings. But as described correctly by @jrowen the mjs_plot should process R objects as x and y variables as shown in his previous comment.

from metricsgraphics.

birdplane-industries avatar birdplane-industries commented on June 12, 2024

This issue has still not been fixed, and I believe it is a very important feature to add for use in Shiny Apps in which the user chooses what fields to plot. And I don't think a fix would be too difficult. I think the real problem is the use of substitute() inside mjs_plot(). This seems to be a dangerous function because it forces any input to be an expression. It will force a variable name to be the character expression of that variable name--not the character string that the variable actually represents. And I see no way around it.

As @jrowen mentions, we should be able to just reverse engineer how ggplot2's aes_string() handles its input parameters.

aes_string <- function (x = NULL, y = NULL, ...) 
{
    mapping <- c(compact(list(x = x, y = y)), list(...))
    mapping[vapply(mapping, is.null, logical(1))] <- "NULL"
    parsed <- lapply(mapping, function(x) parse(text = x)[[1]])
    structure(rename_aes(parsed), class = "uneval")
}

from metricsgraphics.

jrowen avatar jrowen commented on June 12, 2024

Recently, I ran into a similar issue with the rbokeh library, so I made an attempt at a fix here. If you have a minute, please give it a try an let me know if it works for you.

devtools::install_github("jrowen/metricsgraphics", ref = "allow_vrbl_names")

from metricsgraphics.

hrbrmstr avatar hrbrmstr commented on June 12, 2024

@jrowen I shall, but in the meantime folks can try the "mjs_plot_" version in the dev branch - https://github.com/hrbrmstr/metricsgraphics/tree/dev01

I also added an as_mjsplot function to take simple ggplot objects and convert them to metricsgraphics ones

from metricsgraphics.

Related Issues (20)

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.