尝试使用ggplot2填充饼图中的大差距

Nic*_*ler 0 graphics r ggplot2 pie-chart

尝试使用ggplot2创建饼图,但似乎无法在线使用其他参考.我创建的图表缺少大部分填充.

ggplot(sae,aes(x=1,fill=factor(State), width=1))+        
geom_bar()+
ggtitle("House by State")+
coord_polar(theta='y')
Run Code Online (Sandbox Code Playgroud)

此代码给出:

在此输入图像描述

我如何填写中心?

任何其他改进赞赏.

Her*_*oka 5

有样本数据

sae <- data.frame(State=sample(LETTERS[1:6],60,T))


ggplot(sae,aes(x=factor(1),fill=factor(State)))+        
  geom_bar(width=1)+
  ggtitle("House by State")+
  coord_polar(theta="y")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:其他选项(因为饼图很糟糕)

#following Jaaps example: some better way to visualize this
#grouped barchart

p1 <- ggplot(sae, aes(x=State, fill=State)) +
  geom_bar() + labs(title="grouped barchart")


#stacked barchart; especially practical if you want to compare groups
sae$group <- rbinom(60,1,0.5)
p2 <- ggplot(sae, aes(x=factor(group),fill=State))+
  geom_bar(width=0.5) + labs(title="grouped stacked barchart")

do.call(grid.arrange,list(grobs=list(p1,p2),ncol=2))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述