首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R中设置边距

在R中设置边距
EN

Stack Overflow用户
提问于 2019-01-07 18:10:15
回答 1查看 1.1K关注 0票数 0

我在R中做一个箱形图,我想标记我的Y轴。名字很长,所以我想把底部的页边距变大一点,以便把它们都放进去。有人告诉我,我需要做的是使用mar()函数。但是似乎无论我在函数中放入什么值,我的边距都不会改变!

我的盒子图看起来像这样:

我的R脚本如下所示:

代码语言:javascript
复制
boxplot(
  as.numeric(UEC$Q1_1)[3:21],
  as.numeric(UEC$Q1_2)[3:21],
  as.numeric(UEC$Q1_3)[3:21],
  as.numeric(UEC$Q1_4)[3:21],
  as.numeric(UEC$Q1_5)[3:21],
  as.numeric(UEC$Q1_6)[3:21],
  as.numeric(UEC$Q1_7)[3:21],
  as.numeric(UEC$Q1_8)[3:21],
  as.numeric(UEC$Q1_9)[3:21],
  as.numeric(UEC$Q1_10)[3:21],
  as.numeric(UEC$Q1_11)[3:21],
  as.numeric(UEC$Q1_12)[3:21],
  as.numeric(UEC$Q1_13)[3:21],
  as.numeric(UEC$Q1_14)[3:21],
  as.numeric(UEC$Q1_15)[3:21],
  as.numeric(UEC$Q1_16)[3:21],
  as.numeric(UEC$Q1_17)[3:21],
  as.numeric(UEC$Q1_18)[3:21],
  as.numeric(UEC$Q1_19)[3:21],
  as.numeric(UEC$Q1_20)[3:21],
  as.numeric(UEC$Q1_21)[3:21],
  as.numeric(UEC$Q1_22)[3:21],
  as.numeric(UEC$Q1_23)[3:21],
  as.numeric(UEC$Q1_24)[3:21],
  as.numeric(UEC$Q1_25)[3:21],
  as.numeric(UEC$Q1_26)[3:21],
  main="UEC Questions",
  names=c("annoying/enjoyable", "not understandable/understandable",    "creative/dull",    "easy to learn/difficult to learn", "valuable/inferior",    "boring/exciting",  "not interesting/interesting",  "unpredictable/predictable",    "fast/slow",    "inventive/conventional",   "obstructive/supportive", "good/bad",   "complicated/easy", "unlikable/pleasing",   "usual/leading edge",   "unpleasant/pleasant",  "secure/not secure",    "motivating/demotivating",  "meets expectations/does not meet expectations",    "inefficient/efficient",    "clear/confusing",  "impractical/practical",    "organized/cluttered",  "attractive/unattractive",  "friendly/unfriendly", "conservative/innovative"),
  las=2,
  mar=c(5.1, 4.1, 4.1, 2.1) 
  )

我知道我输入的利润率值可能是错误的,但它们无论如何都不起作用!

有没有人能建议我哪里错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-07 18:54:29

您可以在调用boxplot之前使用par

使用cex.axis可以减小x轴的字体大小,使用mar可以随意调整边框周围的间距。

请注意,顺序为mar=c("bottom-side", "left-side", "upper-side", "right-side")

代码语言:javascript
复制
par(cex.axis=0.8, mar=c(8, 4, 5, 2))
boxplot(as.numeric(data$qsec),
        as.numeric(data$mpg),
        names = c("areallylongtext", "anotherreallylongtext"), las=2)

请注意,您不应该复制/粘贴所有这些as.numeric(),而应该使用如下示例中的分组变量:

代码语言:javascript
复制
par(cex.axis=0.8, mar=c(10, 4, 5, 2))
boxplot(mpg ~ cyl, data, 
        names=c("areallylongtext", "anotherreallylongtext", "yetanotherreallylongtext"), las=2)

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

https://stackoverflow.com/questions/54072272

复制
相关文章

相似问题

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