Issue
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))
.
Solution
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:
Which is the same result using ggplot
:
ggplot(df)+geom_bar(aes(var))
Answered By - Quinten Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.