1

このdata.frameを取得しました

'data.frame':   935 obs. of  17 variables:
 $ IQ        : num  93 119 108 96 74 116 91 114 111 95 ...
 $ KWW       : num  35 41 46 32 27 43 24 50 37 44 ...
 $ educ      : num  12 18 14 12 11 16 10 18 15 12 ...
 $ exper     : num  11 11 11 13 14 14 13 8 13 16 ...
 $ tenure    : num  2 16 9 7 5 2 0 14 1 16 ...
 $ age       : num  31 37 33 32 34 35 30 38 36 36 ...
 $ married   : Factor w/ 2 levels "married","non-married": 1 1 1 1 1 1 2 1 1 1 ...
 $ black     : Factor w/ 2 levels "black","non-black": 2 2 2 2 2 1 2 2 2 2 ...
 $ south     : Factor w/ 2 levels "non-south","south": 1 1 1 1 1 1 1 1 1 1 ...
 $ urban     : Factor w/ 2 levels "rural","urban": 2 2 2 2 2 2 2 2 1 2 ...
 $ sibs      : num  1 1 1 4 10 1 1 2 2 1 ...
 $ brthord   : num  2 NA 2 3 6 2 2 3 3 1 ...
 $ meduc     : num  8 14 14 12 6 8 8 8 14 12 ...
 $ feduc     : num  8 14 14 12 11 NA 8 NA 5 11 ...
 $ lwage     : num  6.65 6.69 6.72 6.48 6.33 ...
 $ experclass: Factor w/ 5 levels "(0,5]","(5,10]",..: 3 3 3 3 3 3 3 2 3 4 ...
 $ iqlevel   : Factor w/ 4 levels "50","75","100",..: 2 3 3 2 1 3 2 3 3 2 ...

このようにggplotを描画すると、次のように機能します。

   p<-ggplot(data = wage)
  p+ geom_jitter(aes(x = educ, y = lwage, shape=married,
                col = black, size=IQ, alpha=0.1))

しかし、これは好きではありません

   p<-ggplot(data = wage)
  p+ geom_jitter(aes(x = educ, y = lwage, shape=married,
                col = black, size=iqlevel, alpha=0.1))

エラーはgeom_smoothで発生します。完全なコードは次のとおりです。

  load("C:/tmp/session08.rda")

  wage["iqlevel"]<-cut(wage$IQ, breaks=c(0,75,100,125,Inf), labels=c(50,75,100,125))

  # geom_jitter where col, size, etc define different representations/ axes
  p<-ggplot(data = wage)

  p+ geom_jitter(aes(x = educ, y = lwage, shape=married,
                    col = black, size=iqlevel, alpha=0.1)) +
  # a grid
  facet_grid(urban ~ experclass)+
  # setting the axis labels
  xlab("Education (Years)") + ylab("Log Wage") +
  scale_fill_discrete(name="Experimental\nCondition") 
  # setting the labels for the legend
  labs(shape="Martial Status", col="Ethnicity", size ="IQ") +
  # removing alpha from the legend and setting dots as the symbol of the size legend
  guides(alpha=FALSE, size = guide_legend(override.aes = list(shape = 20))) +
  # trying to draw a regression, without the confidence interval
  geom_smooth(se=F, method ="lm", color="black", fullrange=T, na.rm=T,
              aes(lwd=1, x = educ, y = lwage)) 

編集:

賃金を含むセッションファイル: session08.rda

PS:IQレベルはカスタムでなければならないので、ファクターレベルを設定する必要があります

4

1 に答える 1

3

lwd有効なgeom_smooth美的パラメータではありません。size=1と同じように、美的機能の外側に設定しcolor="black"ます。

これがドキュメントのリンクです。

于 2012-11-21T18:46:05.493 に答える