Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 拆分饼图上的分组值_R_Googlevis - Fatal编程技术网

R 拆分饼图上的分组值

R 拆分饼图上的分组值,r,googlevis,R,Googlevis,已经为下面提到的需求构建了一个定制的R脚本 我们的客户希望他们的数据显示在饼图中,但我们在饼图中使用的维度有16个值。 要求分别显示前9个值,其余值(16-9=7)分组为一个值(与其他值一样),以便显示所有值 对于上述要求,我已使用 suppressPackageStartupMessages(library(googleVis)) library(dplyr) df=data.frame(Function=(Current_Model_Salary_All_Dimensions$'Groupe

已经为下面提到的需求构建了一个定制的R脚本

我们的客户希望他们的数据显示在饼图中,但我们在饼图中使用的维度有16个值。 要求分别显示前9个值,其余值(16-9=7)分组为一个值(与其他值一样),以便显示所有值

对于上述要求,我已使用

suppressPackageStartupMessages(library(googleVis))
library(dplyr)
df=data.frame(Function=(Current_Model_Salary_All_Dimensions$'Grouped Function'),Amount=c(Current_Model_Salary_All_Dimensions$Amount))
df <- df %>% group_by(Function) %>% summarise(Amount = sum(Amount)) %>% arrange(desc(Amount))
df <- rbind(top_n(df,9), slice(df,10:n()) %>% summarise(Function="Others",Amount=sum(Amount)))
plot(gvisPieChart(df,options=list(width=500, height=500)))
suppressPackageStartupMessages(库(谷歌视讯))
图书馆(dplyr)
df=data.frame(函数=(当前模型工资所有维度$分组函数),金额=c(当前模型工资所有维度$金额))
df%按(职能)分组%>%汇总(金额=总额(金额))%%>%排列(说明(金额))
df%汇总(Function=“Others”,Amount=sum(Amount)))
绘图(gvisPieChart(df,选项=列表(宽度=500,高度=500)))
截图:


但是现在有一个小小的变化,如果我们在饼图中选择其他人,它能显示其他人中包含的所有内容及其百分比吗。

我的理解是正确的,您的代码没有实现您想要的功能,因为您想添加一些功能来生成“其他”类别的摘要?Ps请尝试创建一些虚拟数据,允许用户重现您的示例——这使您有更多机会获得有用的asnwer。关于在您的问题中提供数据的一些提示: