ggplot躲过了barplot [英] ggplot dodged barplot
问题描述
我想从以下数据框中创建一个barplot:
$ (2.4,3,3,3.16,2.5,2.5,3,4.5)
sds <-c(1.0,1.2),b
,1.0,1.1,2.1,0.7,2.8,0.7)
个队<-c(1,1,1,1,2,2,2,2)
个比例<-c(1 ,2,3,4,1,2,3,4)
data < - data.frame(teams,scale,means,sds)
在此之前,它运行良好,我得到了一张照片,其中蓝色和红色旁边标有偏差。
pre $ lt; code> graph< - ggplot(data = datas,aes(scales,y = means))
graph +
geom_bar(aes(fill =球队),stat =身份,position =dodge)+
no_margins +
geom_errorbar(aes(ymin =平均值= sds,ymax =平均值+ sds,宽度= 0.2),position = position_dodge (宽度= 0.90))+
coord_flip()
安装最新版本的R (2.15.1),我得到的只是一个文件,其中4个栏显示为蓝色而不是躲闪(彼此旁边)
有没有人有一个想法,其中的变化(颜色,闪避)从哪里来?
我花了好几个小时的结果,所以非常感谢您的任何建议! / b>我不确定它为什么不能正常工作,但是这里有一个版本。
graph < -
ggplot(data = datas,aes(scales,y = means,group = teams))+
geom_bar(aes(fill = teams),stat =identity,
position =dodge)+
geom_errorbar(aes(ymin =平均值= sds,ymax =平均值+ sds,宽度= 0.2),
position = position_dodge(width = 0.90))+
coord_flip()
我把 group = teams $ c $进入美学;它不应该是必须的,因为您在
geom_bar
中有一个 fill = teams
。
I'm desperately looking for a solution for this problem:
I want to create a barplot from the following dataframe:
means <- c(2.4,3,3,3.16,2.5,2.5,3,4.5)
sds <- c(1.0,1.2,1.0,1.1,2.1,0.7,2.8,0.7)
teams <- c(1,1,1,1,2,2,2,2)
scales <- c(1,2,3,4,1,2,3,4)
datas <- data.frame(teams, scales, means, sds)
Before, it worked well and I got a picture which where beside each other in blue and red with standard deviations.
graph <- ggplot(data=datas, aes(scales, y=means))
graph +
geom_bar(aes(fill=teams), stat="identity", position="dodge") +
no_margins +
geom_errorbar(aes(ymin= means - sds, ymax = means + sds, width=0.2), position=position_dodge(width=0.90)) +
coord_flip()
After installing the latest version of R (2.15.1), all I get is a file, where the 4 bars appear in blue and not dodged (beside each other)
Does anyone have an idea, where the change (colour, dodge) came from?
I have spent hours for results, so thank you very much for any recommendations!
I'm not sure why it isn't working right, but here is a version that does.
graph <-
ggplot(data=datas, aes(scales, y=means, group=teams)) +
geom_bar(aes(fill=teams), stat="identity",
position="dodge") +
geom_errorbar(aes(ymin= means - sds, ymax = means + sds, width=0.2),
position=position_dodge(width=0.90)) +
coord_flip()
I put group=teams
into the aesthetics; it shouldn't be necessary because you have a fill=teams
in geom_bar
.
这篇关于ggplot躲过了barplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!