Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.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_Graph_Waffle Chart - Fatal编程技术网

R 华夫格图不显示一组

R 华夫格图不显示一组,r,graph,waffle-chart,R,Graph,Waffle Chart,我使用库(华夫格) 我的问题是姓氏组没有出现。我使用的代码如下 counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 ) counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", &quo

我使用
库(华夫格)

我的问题是姓氏组没有出现。我使用的代码如下

counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 )
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                  scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
Generation_graph<-waffle(counts)+ scale_fill_tableau(name=NULL)

问题是,你的第七类的价值只是太小,无法在情节中体现出来。最后一个不带标签的组只是反映默认情况下由华夫格添加的“正方形”,以“填充”最后一列

根据您想要实现的目标,有几种选择:

库(华夫格)
#>加载所需包:ggplot2
图书馆(主题)

计数您可以使用
scale\u fill\u manual()

library(ggthemes)
library(waffle)
counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 )
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                      scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
Generation_graph<-waffle(counts) + 
  scale_fill_manual(values = c("red", "blue", "green", "purple", "pink", "yellow", "orange", "blue"),
                    labels = counts_names, 
                    drop = TRUE)
库(ggthemes)
图书馆(华夫饼)
计数
library(ggthemes)
library(waffle)
counts<-c(135.92, 15.98, 14.97, 14.15, 5.82, 11.82, 0.07 )
counts_names<-sprintf("%s (%s)", c("Coal", "Gas", "Wind", "Hydro", "Grid-scalar solar", "Rooftop solar", "Storage systems"), 
                      scales::percent(round(counts/sum(counts), 4)))
names(counts)<-counts_names
Generation_graph<-waffle(counts) + 
  scale_fill_manual(values = c("red", "blue", "green", "purple", "pink", "yellow", "orange", "blue"),
                    labels = counts_names, 
                    drop = TRUE)