2017-04-23 3 views
1

私はボックスプロットを作成し、x-ラベルをx軸に対して垂直に設定しました。これにより余白を調整して実際のx軸titleはx軸ラベルと重複しません。しかし、そのようにすると、y軸のタイトルは遠くまで同じように移動され、y軸との間に大きなギャップがあることを意味します。これを修正して別々に変更する方法はありますか?ボックスプロットのマージンを個別に調整することはできません

boxplot(spend~region, data=spendbyregion, main="Boxplot showing distribution 
of expense by location", 
     xlab="expense", ylab="location", las=2) + 
    theme(axis.title = element_text(family = "Trebuchet MS", color = "#111111", face ="bold", size=20, hjust=0.5)) 
    par(mar=c(14, 15, 4.1, 2.1), mgp=c(10.5,1,0)) 

Boxplot

+0

多分あなたは 'ggplot2'を使う必要があります。 –

+0

コードを使用できるようにサンプルデータを提供してください。最も良い方法は 'dput(spendbyreligion)'を使用することです – G5W

答えて

0

私はここに対処するそのあなたのコードに問題はなく、全ての数があります。あなたの鍵となる問題は、par関数の引数mgpの使用のようです。 mgpは、両方の軸に対して有効です。

mai(余白をインチで設定)、cex.axis(軸ラベルのフォントサイズ)で遊んでも構いません。それでも同じ方法で両方の軸を扱うと、問題が生じます。 X軸のタイトルの発生を抑制し、xtext()

# First creating some mimicking data 
regions <- c("East Midlands", "Eastern", "London", "Norht East", "North West Merseyside", 
      "Northern Ireland", "Scotland", "South East", "South West", "Wales", "West Midlands", 
      "Yorkshire and the Humber") 
spendings <- rnorm(1200, mean = 350, sd = 6) 
spendbyregion <- data.frame(spend = spendings, region = rep(regions, 100)) 

# increase the bottom margin 
# to be called before plotting 
par(mai = c(2.0, 0.8, 0.8, 0.4)) 

# create plot; suppress xlab; decrease font size of axis labels 
boxplot(spend ~ region, data = spendbyregion, main = "Boxplot showing distribution 
     of expense by location", xlab = "", ylab = "expense", las = 2, cex.axis = .7) 

# manually create X axis label 
mtext(text = "location", side = 1, line = 8) 

# reset defaults 
par(mar = c(5, 4, 4, 2), 
    mgp = c(3, 1, 0), 
    mai = c(1.0, 0.8, 0.8, 0.4)) 

を手動で作成する、これはあなたが望むものである場合は私に知らせてください:

次の作業を行います。

+0

はい、これはまさにそれでした、ありがとう! – LoriDori

+0

@Wary私の喜び。あなたが満足している場合は、答えを「有益」および/または「選択された解決策」としてマークしてください。ありがとうございました ! – KoenV

関連する問題