首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在r中单独调整方框页边距

无法在r中单独调整方框页边距
EN

Stack Overflow用户
提问于 2017-04-23 09:19:49
回答 1查看 1.8K关注 0票数 1

我创建了一个方框,并将x标签设置为垂直于x轴,这迫使我调整页边距,这样实际的x轴标题就不会与x轴标签重叠。然而,在这样做的时候,y轴的标题被移动到了同样远的地方,这意味着它和y轴之间有很大的差距。有什么办法可以解决这个问题,或许可以单独改变它们吗?

代码语言:javascript
复制
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))

箱形图

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-23 20:21:43

您的代码中有许多问题,我将在这里讨论这些问题。您的关键问题似乎是使用mgp函数的par参数。mgp,对于都是有效的。

您可以使用mai (以英寸为单位设置边距)和cex.axis (轴标签的字体大小)。即使这样,如果你以同样的方式对待两个轴,你就会有一个问题。

以下操作有效:抑制X轴标题的生成,并使用xtext()手动创建它

代码语言:javascript
复制
# 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))

如果这是你想要的,请告诉我。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43569359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档