如何在echarts4r“ e_pie`派中显示计数

发布于 2025-02-12 19:34:05 字数 239 浏览 0 评论 0原文

我有一个包含4个变量的列,这些变量(坏,好,非常好,出色)

我需要计算它们在该列中重复多少,并在Echarts4r中的饼图和bar图中进行比较,并在饼图和条形图中提示

我:df< - data.frame(var = c(“ low”,“ low”,“ low”,“ low”,“ high”))我想要的结果与GGPLOT(DF)+GEOM_BAR(AES(var))

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2025-02-19 19:34:05

首先,您需要创建一个显示每个VAR计数的数据框,然后可以在e_chart中使用e_bar之后使用它:

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:output:

“在此处输入图像描述”

是相同的结果。

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

使用ggplot“在此处输入图像说明”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文