将数据标签添加到R中的spineplot

时间:2017-03-23 16:42:07

标签: r plot label

        <SelectParameters>
            <asp:controlparameter ControlID="DropDownListCustomer" PropertyName="SelectedValue" Name="Customer_Name" />
            <asp:querystringparameter QueryStringField="C" Name="C" />
            <asp:controlparameter ControlID="DropDownListContract" PropertyName="SelectedValue" Name="Order_Number" />
            <asp:querystringparameter QueryStringField="O" Name="O" />
            <asp:controlparameter ControlID="UserID" PropertyName="Text" Name="username" />
            <asp:querystringparameter QueryStringField="U" Name="U" />
            <asp:controlparameter ControlID="DropDownListLocation" PropertyName="SelectedValue" Name="Warehouse_Id" />
            <asp:querystringparameter QueryStringField="W" Name="W" />
        </SelectParameters>

出于某种原因,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) 函数仅绘制远离图表右侧的一个标签。我使用这种格式将数据标签应用于其他类型的图形,所以我很困惑。

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

1 个答案:

答案 0 :(得分:1)

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

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

你会得到像

这样的东西

Here's

这显然不是标签的正确位置,但您应该能够自己解决这个问题。 (您将不得不从累积频率中减去每个条形图的一半频率,并考虑到条形图被填充了一定量的空白。