【问题标题】:Add data labels to spineplot in R在R中将数据标签添加到spineplot
【发布时间】:2017-03-23 16:42:06
【问题描述】:
iFacColName <- "hireMonth"

iTargetColName <- "attrition"

iFacVector <- as.factor(c(1,1,1,1,10,1,1,1,12,9,9,1,10,12,1,9,5))

iTargetVector <- as.factor(c(1,1,0,1,1,0,0,1,1,0,1,0,1,1,1,1,1))

sp <- spineplot(iFacVector,iTargetVector,xlab=iFacColName,ylab=iTargetColName,main=paste0(iFacColName," vs. ",iTargetColName," Spineplot"))
spLabelPass <- sp[,2]/(sp[,1]+sp[,2])
spLabelFail <- 1-spLabelPass
text(seq_len(nrow(sp)),rep(.95,length(spLabelPass)),labels=as.character(spLabelPass),cex=.8)

出于某种原因,text() 函数仅在图形右侧绘制一个标签。我已经使用这种格式将数据标签应用于其他类型的图表,所以我很困惑。

编辑:添加更多代码以使示例工作

【问题讨论】:

  • 什么是 iFacColName 和 iTargetColName?
  • 抱歉,修改了代码

标签: r plot label


【解决方案1】:

您没有将标签放置在绘图区域内。它仅在 x 轴上延伸到 1.3 左右。尝试绘制类似的东西

text(
  cumsum(prop.table(table(iFacVector))),
  rep(.95, length(spLabelPass)),
  labels = as.character(round(spLabelPass, 1)),
  cex = .8
)

你会得到类似的东西

这显然不是标签的正确位置,但您应该能够自己弄清楚。 (您将不得不从累积频率中减去每个条的频率的一半,并考虑到这些条被填充了一些空白的事实。

【讨论】:

    猜你喜欢
    • 2016-01-13
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多