本文介绍了做成对的倒立直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想在一组不同的测试中为两组配对的点图直方图,其中两组在y轴上以相反的方向显示。使用这个简单的数据集 dat 我可以制作像这样的多面斑点图 ggplot(dat,aes(score,fill = group) )+ facet_wrap(〜test)+ geom_dotplot(binwidth = 1,dotsize = 1) 但我希望Control点指向而不是起来。使用这个问题和答案,我可以制作一个柱状图版本看起来或多或少像我想要的那样 ggplot()+ geom_histogram(data = subset(dat,group ==实验),aes(score,fill =Experimental,y = ..count ..))+ geom_histogram(data = subset(dat,group ==Control),aes(score ,fill =Control,y = - .. count ..))+ scale_fill_hue(Group) 但现在刻面已经消失。我知道我可以使用 grid.arrange 来手动完成构造,但这样做会很费力(我的实际数据集有很多测试,而不仅仅是2个),还有更优雅解决方案? 两个后续问题: geom_histogram 会给我一个警告,说明当ymin!= 0时堆叠不好定义。有谁知道它是如何不明确?换句话说,这是我应该关注的吗? 我宁愿使用dotplot代替直方图,但反转似乎不适用于dotplot。这是为什么?任何想法如何得到它的工作? 预先感谢!解决方案仔细阅读 geom_dotplot 将产生分红: ggplot()+ facet_wrap(〜test)+ geom_dotplot(data = subset(dat,group ==Experimental),aes(score,fill =Experimental ))+ geom_dotplot(data = subset(dat,group ==Control),aes(score,fill =Control),stackdir =down)+ scale_fill_hue(Group ) 我不知道顶部的 stackdir 参数我的头。我必须查看它! I would like to make paired dotplot histograms for two groups across a set of different tests with the two groups shown in opposite directions on the y-axis. Using this simple data setdat <- data.frame(score = rnorm(100), group = rep(c("Control", "Experimental"), 50), test = rep(LETTERS[1:2], each=50))I can make faceted dotplots like thisggplot(dat, aes(score, fill=group)) + facet_wrap(~ test) + geom_dotplot(binwidth = 1, dotsize = 1)but I want the Control dots to be pointing down rather than up. Using this question and answer, I can make a histogram version that looks more or less like what I wantggplot() + geom_histogram(data=subset(dat, group=="Experimental"), aes(score, fill="Experimental", y= ..count..)) + geom_histogram(data=subset(dat, group=="Control"), aes(score, fill="Control", y= -..count..)) + scale_fill_hue("Group")but now the faceting is gone. I know I could do the faceting manually using grid.arrange, but that would be laborious (my actual data set has many tests, not just 2), is there a more elegant solution?Two follow-up questions:geom_histogram is giving me a warning that says "Stacking not well defined when ymin != 0". Does anyone know how "not well defined" it is? In other words, is this something I should be concerned about?I'd prefer to use dotplot instead of histogram, but the inversion doesn't seem to work for dotplot. Why is that? Any ideas how to get it to work?Thanks in advance! 解决方案 A careful reading of geom_dotplot will pay dividends:ggplot() + facet_wrap(~test) + geom_dotplot(data=subset(dat, group=="Experimental"), aes(score, fill="Experimental")) + geom_dotplot(data=subset(dat, group=="Control"), aes(score, fill="Control"),stackdir = "down") + scale_fill_hue("Group")I didn't know of the stackdir argument off the top of my head. I had to look it up! 这篇关于做成对的倒立直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 14:56