Create a histogram for weighted values

前端 未结 3 487
醉酒成梦
醉酒成梦 2020-12-06 16:33

If I have a vector (e.g., v<-runif(1000)), I can plot its histogram (which will look, more or less, as a horizontal line because v is a sample f

相关标签:
3条回答
  • 2020-12-06 17:05

    Package plotrix has a function weighted.hist which does what you want:

    w<-seq(1,1000)
    v<-sort(runif(1000))
    weighted.hist(v, w)
    

    Example of <code>weighted.hist</code>

    0 讨论(0)
  • 2020-12-06 17:06

    An alternative from the weights package is wtd.hist()

    w<-seq(1,1000) v<-sort(runif(1000)) wtd.hist(x=v,weight=w)

    0 讨论(0)
  • 2020-12-06 17:12
    library(ggplot2)
    w <- seq(1,1000)
    v <- sort(runif(1000))
    
    foo <- data.frame(v, w)
    
    ggplot(foo, aes(v, weight = w)) + geom_histogram()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题