2

在此处输入图像描述df

Date       Team    Country   Score
1/1/2012   TeamA   Germany  10
1/2/2012   TeamA   Germany  25
1/3/2012   TeamA   Germany  50
1/1/2012   TeamB   France  10
1/2/2012   TeamB   France  70
1/3/2012   TeamB   France  50

我想创建带有 ggplot 的 facet wrap graph 以具有标题,并将国家/地区放在每个图的左侧,如图所示。这对ggplot可行吗?

ggplot(df,aes(Date, Score, group=Team, colour=Team))+ 
        geom_point(size=0.5) + 
        geom_smooth(method="lm", se=T, size=1) + 
        facet_wrap(~Team, scale="free")

在此处输入图像描述

4

1 回答 1

1

我定义

dat.text
   Team Country x  y
3 TeamA Germany 3 30
4 TeamB  France 3 15

使用 geom_text

 p + geom_text(aes(x, y, label=Country, group=NULL),data=dat.text,
               angle =90,family = "mono",size=12)
    + theme(legend.position = "none")

在此处输入图像描述

想法:我使用一个包含三条信息的新数据框并将其提供给 geom_text。

ggplot 完成剩下的工作。

  • 坐标 (x,y)
  • 多面变量级别:团队
  • 要提供的标签:国家

    要将文本放在 plot 的右侧,我选择

     dat.text$x  <- tail(originalData$Date,1) 
    
于 2012-12-07T15:27:24.343 回答