When I create bar chart below in R, there was no problem but when I convert these code to shiny function, the problem is occur, could you help ?
Bar chart in normal R code:
path <- "WA_Fn-UseC_-HR-Employee-Attrition.csv (job attrition)"
data <-fread(path)
# bar chart function function
Categorical_vs_categorical_plot_2 <- function(data,group_col,fill_col){
data %>%
ggplot(aes_(x = fill_col, group = group_col)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)),
stat="count",
alpha = 0.7) +
geom_text(aes(label = scales::percent(..prop..), y = ..prop.. ),
stat= "count",
vjust = 2) +
labs(y = "Percentage", fill= "Education") +
facet_grid(~Attrition) +
theme_minimal()+
theme(legend.position = "none", plot.title = element_text(hjust = 0.5)) +
ggtitle("Attrition")
}
Categorical_vs_categorical_plot_2(data,~Attrition,~BusinessTravel)
Normal bar chart
Bar chart convert to shiny code [error occur, not show facet_grid and text value like normal bar chart above] :
output$cat_vs_cat_chart2 <- renderPlot({
data() %>%
#ggplot(aes_(x = input$cat_compare, group = ~Attrition)) +
ggplot(aes_(x = 'BusinessTravel', group = ~Attrition)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)),
stat="count",
alpha = 0.7) +
geom_text(aes(label = scales::percent(..prop..), y = ..prop.. ),
stat= "count",
vjust = 2) +
#labs(y = "Percentage", fill= "Education") +
facet_grid(~Attrition) +
theme_minimal()+
theme(legend.position = "none", plot.title = element_text(hjust = 0.5)) +
ggtitle("Attrition")
})
Error bar chart
question from:
https://stackoverflow.com/questions/66058715/ggplot-bar-chart-not-show-correctly-on-shiny-got-answers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…