I'm trying to create a plotly barchart using some tidyeval functionality. I have succeeded in creating a simple barchart but can not seem to make a stacked barchart colored by an attribute. Have been stuck at this for a while and cannot seem to figure out what the error is saying. Any help is appreciated, Thanks!
get_barchart <- function(df, col, xcol, y){
a <- sym(col)
col <- enquo(a)
xcol <- enquo(xcol)
y_col <- enquo(y)
df %>%
group_by(!!col, !!xcol) %>%
summarise(Total = sum(!!y_col, na.rm = T)) %>%
plot_ly(x = xcol, y = ~Total, type = "bar",
color = col,
text = ~Total, textposition = 'auto') %>%
layout(barmode = 'stack')
}
x = "Gender"
get_barchart(data.frame(UCBAdmissions), x, Admit, Freq)
If I comment out the color line, the function works so I'm pretty sure that is what is causing the error but can not seem to understand why.