Home > Software engineering >  how to Showing counts in echarts4r `e_pie` pie ,charts bar charts in R
how to Showing counts in echarts4r `e_pie` pie ,charts bar charts in R

Time:07-02

I have a column that contains 4 variables which are( Bad , Good , Very Good , Excellent )

I need to count how much they repeats in that column and compare each of them and presint to me in pie chart and bar chart in echarts4r

For example : df <- data.frame( var = c("low","low","low","high") ) i want the same result as ggplot(df) geom_bar(aes(var)).

CodePudding user response:

First you need to create a dataframe which shows the count per var and after that you can use this in e_chart with e_bar like this:

df <- data.frame( var = c("low","low","low","hight") )
library(dplyr)
library(echarts4r)

df_result <- df %>% 
  count(var) %>% 
  arrange(n)

plot <- df_result %>%
  e_charts(x = var) %>%
  e_bar(n, legend = FALSE, name = "var")

Output:

enter image description here

Which is the same result using ggplot:

ggplot(df) geom_bar(aes(var)) 

enter image description here

  • Related