【问题标题】:R lattice histogram add the mean as text to each histogramR lattice histogram 将平均值作为文本添加到每个直方图
【发布时间】:2014-06-15 22:58:37
【问题描述】:

根据前面回答的问题,我认为以下脚本应该可以工作。

require(lattice)

histogram(cyl~mpg|gear*am,
        data=mtcars,
        nint=5,
        panel=function(y,...){
            panel.histogram(...)
            m<-mean(y)
            panel.txt(x=30,y=60,labels=m)
        }
)

直方图,但我得到“数据包 1 参数“y”丢失,没有默认值”

感谢您的帮助,因为我在这个谜题上浪费了一个小时。

【问题讨论】:

  • 您要打印什么值?直方图是一个单变量图,没有明确的y 值(即在此处传递cyl 无效)。

标签: r histogram lattice


【解决方案1】:

panel.histogram 需要一个x 参数(不是y 参数),这是histogram 传递给面板的线索。

此外,您需要通过将 x 参数包含在参数列表中来将其传递给 panel.histogram

最后是panel.text,而不是panel.txt

histogram(cyl~mpg|gear*am,
          data=mtcars,
          nint=5,
          panel=function(x, ...){
              panel.histogram(x=x,...)
              m<-mean(x)
              panel.text(x=30,y=60,labels=m)
          }
)

【讨论】:

    猜你喜欢
    • 2011-09-27
    • 2021-01-31
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 2015-01-13
    • 2016-11-30
    • 1970-01-01
    • 2022-12-19
    相关资源
    最近更新 更多