PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 28, 2022

[FIXED] how to Showing counts in echarts4r `e_pie` pie ,charts bar charts in R

 November 28, 2022     bar-chart, echarts4r, pie-chart, r     No comments   

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:

enter image description here

Which is the same result using ggplot:

ggplot(df)+geom_bar(aes(var)) 

enter image description here



Answered By - Quinten
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing