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)