我试图制作带有文字标签的叠加条形图,这是一些示例数据/代码:
library(reshape2)
ConstitutiveHet <- c(7,13)
Enhancer <- c(12,6)
FacultativeHet <- c(25,39)
LowConfidence <- c(3,4)
Promoter <- c(5,4)
Quiescent <- c(69,59)
RegPermissive <- c(23,18)
Transcribed <- c(12,11)
Bivalent <- c(6,22)
group <- c("all","GWS")
meanComb <- data.frame(ConstitutiveHet,Enhancer,LowConfidence,Promoter,Quiescent,RegPermissive,Transcribed,Bivalent,group)
meanCombM <- melt(meanComb,id.vars = "group")
ggplot(meanCombM,aes(group,value,label=value)) +
geom_col(aes(fill=variable))+
geom_text(position = "stack")+
coord_flip()
文本标签出现乱序,它们似乎是预期顺序的镜像。 (无论是否有coord_flip()
)
海报在这里有类似的问题: ggplot2: add ordered category labels to stacked bar chart
对他们的帖子的答案反映了我试过的组中值的顺序(见下文),在图上产生的顺序并不是我能够弄清楚的。这种方法看起来很麻烦,这里有错误还是我错过了什么?
x <- c(rev(meanCombM[meanCombM$group=="GWS",]$value),rev(meanCombM[meanCombM$group=="all",]$value))
ggplot(meanCombM,aes(group,value,label=x)) +
geom_col(aes(fill=variable))+
geom_text(position = "stack")+
coord_flip()
答案 0 :(得分:2)
ggplot(meanCombM,aes(group,value,label=value)) +
geom_col(aes(fill=variable))+
geom_text(aes(group=variable),position = position_stack(vjust = 0.5))+
coord_flip()
Hadley在ggplot2的git存储库中回答了类似于我自己的问题:https://github.com/tidyverse/ggplot2/issues/1972
显然是默认的分组行为(请参阅:
http://ggplot2.tidyverse.org/reference/aes_group_order.html)未在此处正确对数据进行分区,而未指定group
美学,在此示例中,fill
应与geom_col
中的<kendo-combobox
#orgParentId
formControlname="parentId"
[data]="organizationsLike"
[textField]="'name'"
[valueField]="'id'"
[filterable]="true"
(filterChange)="handleFilter($event)"
[placeholder]="'Search parent...'"
[suggest]="true"
[valuePrimitive]="true"
(selectionChange)="parentIdSelChanged($event)"
>
</kendo-combobox>
相同。