1

次のデータ フレームを使用します。

day <- c("Mon","Tues","Wed","Thurs","Fri","Sat","Sun","Week","Mon","Tues","Wed","Thurs","Fri","Sat","Sun","Week")
day <- factor(day, level=c("Mon","Tues","Wed","Thurs","Fri","Sat","Sun","Week"))
month<-c("Jan","Jan","Jan","Jan","Jan","Jan","Jan","Jan","Feb","Feb","Feb","Feb","Feb","Feb","Feb","Feb")
month<-factor(month,level=c("Jan","Feb"))
snow<-gl(1,16,labels=c("Y"))
snow<-factor(snow,levels=c("Y","N"))
count <- c(4,5,6,8,3,4,9,5.57,2,4,3,7,1,9,3,4.14)
d <- data.frame(day=day,count=count,month=month,snow=snow)

バー ラベルは、正しい月のバーではなく、週を中心にしています。

ggplot()+geom_line(data=d[d$day!="Week",],aes(x=day, y=count, group=month, colour=month))+geom_bar(data=d[d$day=="Week",],aes(x=day, y=count, fill=month),position="dodge", group=month)+facet_wrap(~snow,ncol=1,scales="free")+scale_x_discrete(limits=levels(d$day))+geom_text(data=d[d$day=="Week",],aes(x=day, y=count,label=paste(month),vjust=1.5),position="dodge",size=3)

月のラベルを適切なバーの中央に表示できますか?

4

1 に答える 1

1

geom_text動作させるには特定の回避サイズが必要です:

p <- ggplot(data=d[d$day=="Week",], aes(x=day , y=count, fill=month)) + 
  geom_bar(position = "dodge", width = 0.8, stat="identity") +
  geom_text(aes(label=month, x=day, y=count), position=position_dodge(width=0.8), vjust=-.6, size=3) + 
  geom_line(data=d[d$day!="Week",], aes(x=day, y=count, group=month, colour=month)) + 
  facet_wrap(~snow,ncol=1,scales="free") + 
  scale_x_discrete(limits=levels(d$day))
p

固定グラフ

于 2013-05-11T02:29:13.767 に答える