本文介绍了将条形图的显示值扩展到多元叠加条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经被告知,最好在SE上将子问题分成多个主题,所以在这里我就去。 我调整了在这个问题中的答案可以在多元堆积条形图。 dnom Region = sample(c(VL,NL),size = 50,replace = TRUE), PrecededByPrep = sample(c(1,0),size = 50,replace = TRUE), Person = sample(c(person,no person),size = 50,replace = TRUE), Time = sample(c(time,no time),size = 50,replace = TRUE)) ggplot.labs< - data.frame(表(dnom))#OR? ggplot.data ggplot.data ggplot(dnom,aes(x = Variant))+ geom_bar(aes(fill = Variant))+ geom_text(data = ggplot.labs,aes(x = Var1,label = Freq,y = Freq / 2),size = 3)+ scale_fill_manual(values = c(paleturquoise3,palegreen3))+ theme_corples()+ labs(x =Variant,y =Frequentie,title =Distributie van varianten)+ guides(fill = FALSE) 但是,您可以看到我不确定如何合并 ddply 和 melt (如这个答案)。我应该怎么处理这个问题?解决方案 我认为在你的链接和你的修改之间的翻译中, 。 #来自问题的较旧编辑的代码。 dnom_labs< - data.frame(table(dnom $ Region,dnom $ Variant)) #建议答案数据< - ddply(dnom_labs,。(Var1) ,变换,pos = cumsum(Freq) - (0.5 * Freq)) ggplot(aes(fill = Var2),stat =identity)+ geom_text(aes(label = Freq,y = pos),size = 3)+ labs(x =Region,y =Frequencies, title =变体的分布) I have been told that it is better to split up sub questions into multiple topics on SE, so here I go.I have adapted the answer in this question to be presentable in a multivariate stacked bar plot. Everything works fine, however the values are not displaying correctly.dnom <- data.frame(Variant = sample(c("iedere","elke"),size = 50,replace = TRUE), Region = sample(c("VL","NL"),size = 50,replace = TRUE), PrecededByPrep = sample(c("1","0"),size = 50,replace = TRUE), Person = sample(c("person","no person"),size = 50,replace = TRUE), Time = sample(c("time","no time"),size = 50,replace = TRUE))ggplot.labs <- data.frame(table(dnom))# OR?ggplot.data <- melt(dnom, id.vars = "Variant")ggplot.data <- ddply(ggplot.labs, .(Var1), transform, pos = cumsum(Freq) - (0.5 * Freq))ggplot(dnom, aes(x=Variant)) + geom_bar(aes(fill=Variant)) + geom_text(data=ggplot.labs, aes(x=Var1, label=Freq, y=Freq/2), size=3) + scale_fill_manual(values = c("paleturquoise3", "palegreen3")) + theme_corpling() + labs(x="Variant", y="Frequentie", title="Distributie van varianten") + guides(fill=FALSE)But as you can see I am not sure how to merge ddply and melt (as provided in this answer). How should I go about this? 解决方案 I think something was lost in translation between the answer you linked to and your adaptation of it.# Code from an older edit of the question.dnom_labs <- data.frame(table(dnom$Region, dnom$Variant))# Suggested answerData <- ddply(dnom_labs, .(Var1), transform, pos = cumsum(Freq) - (0.5 * Freq))ggplot(Data, aes(x=Var1, y = Freq)) + geom_bar(aes(fill=Var2), stat = "identity") + geom_text(aes(label = Freq, y = pos), size = 3) + labs(x="Region", y="Frequencies", title="Distribution of variant") 这篇关于将条形图的显示值扩展到多元叠加条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 11:08