目的性
创建一个堆叠的区域图或“堆叠”的圆圈图(见图)。不需要饼形图。
数据和条形图的代码
#Data set:
Numbers 16%
Frosts 2%
Doors 6%
Shelfs 10%
Earning -3%
par(mai=c(2, 1, 1, 1), lwd=2)
barplot(as.numeric(c(16, 2, 6, 10, -3)), col = c("lightblue"), main="Bar plot",
names.arg=c("Numbers","Frosts","Earning", "Doors","Shelfs"), xpd=TRUE, las=2, lwd=2,
axes=FALSE, axis.lty=1, cex.axis=1, cex.names=1, cex.main=1, ylim=c(-4, 18), xlim=c(0, 5))两个输出选项

发布于 2015-12-14 15:10:56
这会让你大老远地走到那里
library(ggplot2)
df<- data.frame(value=as.numeric(c(16, 2, 6, 10, -3)),
cat=c("Numbers","Frosts","Earning","Doors","Shelfs"))
ggplot(df[order(df$value),], aes(x=1, y=abs(value), fill=factor(ifelse(value>0, 0, 1)))) +
geom_bar(stat="identity", colour="grey") +
geom_text(aes(label=paste(cat, value)), position = "stack", vjust = 3) +
scale_fill_manual(values=c("white", "red"))

ggplot(df[order(df$value),], aes(x=1, y=abs(value), fill=factor(ifelse(value>0, 0, 1)))) +
geom_bar(stat="identity", colour="grey") +
geom_text(aes(label=paste(cat, value)), position = "stack", vjust = -1) +
scale_fill_manual(values=c("white", "red")) +
coord_polar()

您可能需要修改the值来更改标签的位置,或者为它们计算自定义的y映射,但这是一个好的开始。
发布于 2015-12-14 15:06:49
您可以尝试使用以下方法:
library(ggplot2)
data<-data.frame(Name=c("Earning","Frosts","Doors","Shelfs","Numbers"),Val=c(1,2,6,10,16))
ggplot(data,aes(x=factor(1),y=Val,fill=Name))+
geom_bar(stat="identity",width=1)+coord_polar()只需更改调色板并随时随地添加文本(当然,如果Val列中的第一个值在绘图中太大--它对应于您的负值)

发布于 2015-12-14 15:05:47
右边的“相关”链接的topmost应该为您提供构建堆叠条形图所需的大部分信息,但适合您使用的内容如下:
# A vertical matrix containing the values
md <- matrix(c(-3, 16, 2, 6, 10), ncol=1)
d <- barplot(md, col=c(2, rep(0, 4)))
# Finding the vertical position for the labels
ypos <- apply(md, 2, cumsum)
ypos <- ypos - md/2
ypos <- t(ypos)
# I haven't checked if the values and names match
text(d/3, ypos, adj=c(0, NA),
paste(c("Earning","Numbers","Frosts","Doors","Shelfs"), md, sep=": "))

https://stackoverflow.com/questions/34269029
复制相似问题