【问题标题】:Show labels in X axis in R在 R 中的 X 轴上显示标签
【发布时间】:2021-01-04 05:50:46
【问题描述】:

我正在绘制流量数据的箱线图,但它没有在 x 轴上显示所有站点的名称。如图所示,箱线图在两个站点名称之间保留一个空名称。如何显示所有电台的名称?

这是我的代码

boxplot(mean~station,DSF_moments, col="cyan", ylab ="mean flow [m3/s]", main="Boxplot of mean annual flow for stations at Salt and Verde Rivers", cex=0.5)

这是一张图片

【问题讨论】:

  • 这会自动发生,因此标签不会重叠。您可能想要手动构建自定义的 x 轴;试试boxplot(..., axes=FALSE); axis(1, cex.axis=0.5); axis(2, cex.axis=1);box()
  • 要添加到 jay.sf,您可以通过将字体大小减小到非常小的值或翻转坐标来轻松确认这是真的(+coord_flip() 以查看它们然后显示。
  • @Fnguyen OP 并不是在谈论 ggplot2

标签: r time time-series label boxplot


【解决方案1】:

这里是一个如何使用boxplot 自定义轴的示例。

op <- par(mfrow=c(1, 2))  ## set par

## left panel
boxplot(v ~ g, dat, cex=0.5)

## right panel
boxplot(v ~ g, dat, cex=0.5, axes=F)
labs <- unique(dat$g)
axis(1, seq(labs), labels=FALSE)
axis(2, cex.axis=1)
mtext(labs, 1, 1, at=seq(labs), las=2, cex=.8)
box()

par(op) ## reset par


数据:

dat <- data.frame(v=rnorm(1200), g=month.name)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2014-06-29
    • 2021-08-12
    • 2021-04-18
    • 2019-07-28
    • 2021-12-03
    相关资源
    最近更新 更多