我创建了一个箱线图,并将x标签设置为垂直于x轴,然后强制我调整边距,使实际的x轴标题不与x重叠。 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))
答案 0 :(得分:0)
您的代码存在许多问题,而不是我将在此处解决的所有问题。您的关键问题似乎是使用mgp
函数的par
参数。 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))
如果这是你想要的,请告诉我。