我创建了一个方框,并将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))发布于 2017-04-23 20:21:43
您的代码中有许多问题,我将在这里讨论这些问题。您的关键问题似乎是使用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))如果这是你想要的,请告诉我。
https://stackoverflow.com/questions/43569359
复制相似问题