ggvis - using a variable to assign “x” property using props

此生再无相见时 提交于 2019-12-11 06:24:58

问题


According to the properties and scales reference and this SO post I should be able to use a props(prop()) call as shown below to create the graph. I'm getting an unintelligible error though.

test_df <- data.frame(cbind(x_vals = letters[1:5],
                            y_vals = 1:5)) 

Graphs correctly:

test_df %>% ggvis(x = ~x_vals, y = ~y_vals) %>% 
  layer_points() 

Has error:

x_val_variable <- "x_vals"

test_df %>% ggvis(y = ~y_vals) %>% 
      props(prop("x", as.name(x_val_variable)) %>% 
      layer_points()

Can anyone help me by telling me what I'm doing wrong?


回答1:


I figured out the correct usage of prop(), it doesn't belong in the %>% chain, it's an argument of ggvis or layer_points(). I still don't understand when you would use props() though.

test_df <- data.frame(cbind(x_vals = letters[1:5],
                            y_vals = 1:5)) 

x_val_variable <- "x_vals"

#you can use either one of these, they are identical
p1 <- prop("x", as.name(x_val_variable))
p2 <- prop("x", parse(text = x_val_variable)[[1]])

test_df %>% ggvis(p1, y = ~y_vals) %>% layer_points()


来源:https://stackoverflow.com/questions/39666748/ggvis-using-a-variable-to-assign-x-property-using-props

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!