0

我已经创建了一个带有绘图结果的函数,但我收到了以下错误消息:错误:Quosures 只能在 quasiquotation 上下文中不被引用。

坏的:

列表(!!myquosure)

好的:

dplyr::mutate(数据, !!myquosure)

当我擦除 enquo() 函数时,它会绘图但不识别颜色的 z 参数如果有人有想法请

f4 <- function(z){
  require("dplyr")
  require("lazyeval")
  require("reshape")
  z <- as_name(z)

plt <- mtcars %>% 
select_(~disp, ~hp, ~mpg, all_of(~z)) %>% 
group_by_at(vars(mpg, z)) %>%
summarise_all(sum) %>%
arrange_(~mpg)


plt1 <- gather(plt, key='variable', value = 'Monto', disp, hp) %>%
    mutate(catvar=paste(mpg, variable, sep='_'))
  
  
  z <- enquo(z)  
  
  
  fig <- plot_ly(plt1)
  fig <- fig %>% add_trace(x= ~catvar, y= ~Monto, color=!!z,
                           type = 'bar', colors= 'BrBG',
                           showlegend = TRUE,
                           hoverinfo = "text",
                           text = ~paste(catvar, '\n Monto:', Monto, 'MM USD \n ', z)) %>%
    layout(barmode = "stack") %>%
    
    layout(xaxis = list(title = ""),
           yaxis = list(title='MM USD', rangemode='tozero',side = 'left',  overlaying = "y2", title = 'MM de USD', showgrid = FALSE, zeroline = FALSE))
  
  return(fig)
  
}

f4('carb')
4

0 回答 0