数据标签位于另一个标签之上 [英] Data labels go on top of the other

查看:198
本文介绍了数据标签位于另一个标签之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自定义面板功能(在在此处找到)在图形上显示数据标签.

I use the custom panel function (found here) to display data labels on the graph.

require(HH)     # also loads: lattice, grid, latticeExtra

# custom panel function
myPanelFunc <- function(...){
  panel.likert(...)
  vals <- list(...)
  DF <- data.frame(x=vals$x, y=vals$y, groups=vals$groups)

  ### some convoluted calculations here...
  grps <- as.character(DF$groups)
  for(i in 1:length(origNames)){
    grps <- sub(paste0('^',origNames[i]),i,grps)
  }

  DF <- DF[order(DF$y,grps),]

  DF$correctX <- ave(DF$x,DF$y,FUN=function(x){
    x[x < 0] <- rev(cumsum(rev(x[x < 0]))) - x[x < 0]/2
    x[x > 0] <- cumsum(x[x > 0]) - x[x > 0]/2
    return(x)
  })

  subs <- sub(' Positive$','',DF$groups)
  collapse <- subs[-1] == subs[-length(subs)] & DF$y[-1] == DF$y[-length(DF$y)]
  DF$abs <- abs(DF$x)
  DF$abs[c(collapse,FALSE)] <- DF$abs[c(collapse,FALSE)] + DF$abs[c(FALSE,collapse)]
  DF$correctX[c(collapse,FALSE)] <- 0
  DF <- DF[c(TRUE,!collapse),]

  DF$perc <- ave(DF$abs,DF$y,FUN=function(x){x/sum(x) * 100})
  ###

  panel.text(x=DF$correctX, y=DF$y, label=paste0(round(DF$perc,1),'%'), cex=0.7)
}

data(ProfChal)
origNames = colnames(ProfChal) # required for myPanelFunc
likert(x=Question ~ . , data=ProfChal[ProfChal$Subtable=="Employment sector",]
       ,main='Is your job professionally challenging?' # title
       ,as.percent=TRUE
       ,panel=myPanelFunc
)

但是,在生成的图形中,我在其他图形的顶部看到了一些标签.为什么只在某些标签上而不是在所有标签上都发生这种情况?

However, in the resulting graph I see some labels on top of the other. Why is this happening only for some of the labels and not all of them?

推荐答案

不确定我是正确的,因为我看不到数据,但看起来第一行(学术界(非学生))回答为0表示强烈不同意,而第四项(私人顾问/个体经营者)的回答为0强烈不同意或不同意,这很可能是问题的原因. 我认为解决方案可能是以下条件:如果0回答了一个选项,则删除标签.

Not sure I am correct since I cannot see the data, but it looks like the first line (Academic (nonstudent)) has 0 answering strongly disagree and 4th (Private consultant/self-employed) has 0 answering Strongly disagree or disagree, which would probably be the cause of the problem. I think the solution to it could be a condition that if 0 have answered an option remove the label.

这篇关于数据标签位于另一个标签之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆