1

長い名前を持つカテゴリ変数 (boxplot など) を含むグラフをプロットする場合、themeggplot2 のコマンドを使用して名前をシフトする必要があります。その後、軸の目盛りとテキストの間の距離も設定できますが、この距離は両方の軸に反映されます。 1 つの軸でのみ必要な時間が必要な場合。サンプルコードの下:

df<-data.frame(X=rnorm(50,0,10),Y=c(rep("Some Text",25),rep("Some Larger Text That Takes Space",25)))

    #classical boxplots
ggplot(df,aes(x=Y,y=X))+geom_boxplot()+theme(axis.text=element_text(size=20),axis.text.x=element_text(angle=45))
    #the x axis labels need to be shifted downwards
ggplot(df,aes(x=Y,y=X))+geom_boxplot()+theme(axis.text=element_text(size=20),axis.text.x=element_text(angle=45),axis.ticks.margin=unit(4,"cm"))
    #now they are shifted but there is unnecessary space on the y-axis

axis.ticks.margin1 つの軸のみに作用するように設定するにはどうすればよいでしょうか?

4

1 に答える 1

2

たとえば、これを試してください:

  library(grid)
  axis.ticks.margin=unit(c(4,-4),'cm'))

したがって、ggplot2呼び出しは次のようになります。

ggplot(df,aes(x=Y,y=X))+
  geom_boxplot()+
  theme(axis.text=element_text(size=20),
        axis.text.x=element_text(angle=45),
        axis.ticks.margin=unit(c(4,-4),'cm'))
于 2013-05-30T15:21:39.997 に答える