ggplot boxplot的位置闪避警告? [英] Position-dodge warning with ggplot boxplot?
问题描述
p < - ggplot(data, aes(d $ score,reorder(d $ names d $ scores,median)))+ geom_boxplot()
我有称为名字和整数的因素,称为分数。
我的代码产生一个图表,但图形没有描述这些方框(只显示行),我得到警告消息,position_dodge需要不重叠的x间隔。我试图用 geom_boxplot(width = 5)
来调整高度和宽度,但是这似乎不能解决问题。任何人都可以提出一个可能的解决方案来解决我的问题吗?
我应该指出我的boxplot比较大,在y轴上有大约200个名称值)。也许这就是问题所在?
组数不是问题;即使只有两组时,我也能看到同样的情况。问题在于, ggplot2
垂直绘制箱形图(沿y连续绘制,沿着x分类),并且您试图水平绘制它们(沿x连续绘制,沿y分类)。
另外,你的例子有几个语法错误,因为我们没有 data
/ d
。
以某些模拟数据开始 示例代码的更正版本: 这是你看到的水平线。 如果您将分类放在x轴上,并且连续放在y轴上,您可以获得 最后,如果要翻转坐标轴,可以使用 I'm trying to make a boxplot with ggplot2 using the following code: I have factors called names and integers called scores. My code produces a plot, but the graphic does not depict the boxes (only shows lines) and I get a warning message, "position_dodge requires non-overlapping x intervals." I've tried to adjust the height and width with I should point out that my boxplot is rather large and has about 200 name values on the y-axis). Perhaps this is the problem? The number of groups is not the problem; I can see the same thing even when there are only 2 groups. The issue is that Also, your example has several syntax errors and isn't reproducible because we don't have Start with some mock data Corrected version of your example code: This is the horizontal lines you saw. If you instead put the categorical on the x axis and the continuous on the y you get Finally, if you want to flip the coordinate axes, you can use 这篇关于ggplot boxplot的位置闪避警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ ($ 1000,sd = 500),
names = sample(LETTERS,1000,replace = TRUE))
ggplot(dat,aes(scores,reorder(names,scores,median)))+ geom_boxplot()
ggplot(dat,aes(reorder(names,scores,median),scores))+ geom_boxplot()
coord_flip()
。如果你正在做更复杂的事情,可能会遇到一些额外的问题,但是对于基本的箱型图而言,它是有效的。
ggplot( dat,aes(reorder(names,scores,median),scores))+
geom_boxplot()+ coord_flip()
p <- ggplot(data, aes(d$score, reorder(d$names d$scores, median))) + geom_boxplot()
geom_boxplot(width=5)
, but this does not seem to fix the problem. Can anyone suggest a possible solution to my problem?ggplot2
draws boxplots vertically (continuous along y, categorical along x) and you are trying to draw them horizontally (continuous along x, categorical along y). data
/d
.dat <- data.frame(scores=rnorm(1000,sd=500),
names=sample(LETTERS, 1000, replace=TRUE))
ggplot(dat, aes(scores, reorder(names, scores, median))) + geom_boxplot()
ggplot(dat, aes(reorder(names, scores, median), scores)) + geom_boxplot()
coord_flip()
. There can be some additional problems with this if you are doing even more sophisticated things, but for basic boxplots it works.ggplot(dat, aes(reorder(names, scores, median), scores)) +
geom_boxplot() + coord_flip()