1

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)).

Jan
  • 4,974
  • 3
  • 26
  • 43
  • Could you please share some reproducible data using `dput(your_dataframe)` in your question above? – Quinten Jul 01 '22 at 19:33
  • for example : df <- data.frame( var = c("low","low","low","hight") ) i want the same result at this formula ggplot(df)+geom_bar(aes(var)) – ِAseel Mohammed Jul 01 '22 at 19:45

1 Answers1

1

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

Quinten
  • 35,235
  • 5
  • 20
  • 53