有許多與你的代碼的問題,並不是所有的我將在這裏討論。您的關鍵問題似乎是使用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))
手動創建它,請讓我知道,如果這是你想要的。
也許你需要使用'ggplot2'。 –
您能否提供一些示例數據以便我們可以使用您的代碼?最好的方法是使用'dput(spendbyreligion)' – G5W