我使用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_tableau(name=NULL)
我如何获得右边七个组的原始图形
更新:阅读其中的一条评论,我发现包括选项labels
使我可以保留所有名称的原始图形。
Generation_graph<-waffle(counts)+ scale_fill_tableau(name=NULL, labels=counts_names)
答案 0 :(得分:2)
问题在于您的第七个类别的值很小,无法显示在绘图中。最后一个没有标签的组仅反映了默认情况下华夫饼添加的“正方形”,以“填充”最后一列。
根据要达到的目标,有几种选择:
library(waffle)
#> Loading required package: ggplot2
library(ggthemes)
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
colors
参数设置颜色。在这种情况下,最后一个类别将显示在图例中,而不显示在情节中。也。在这种情况下,最后一列将不被填充。waffle(counts, colors = tableau_color_pal()(length(counts)))
ceiling()
来代替原始数据。最后一个类别在图和图例中都得到体现。waffle(ceiling(counts), colors = tableau_color_pal()(length(counts)))
ceiling()
,请让waffle
选择颜色,并用scale_fill_manual
选择ovveride:waffle(ceiling(counts)) + scale_fill_tableau()
答案 1 :(得分:0)
您可以使用scale_fill_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)