簡體   English   中英

創建一個函數以R中的hist更改直方圖中的bin大小

[英]Create a function to change bin size in a histogram with hist in R

編寫一個接受向量,整數向量,主軸標簽和x軸標簽的函數。 此函數應迭代整數向量中的每個元素,並為每個整數值生成直方圖,將bin計數設置為輸入向量中的元素,並使用指定的參數標記main和x軸。 您應該標記y軸以讀取頻率,bins =和bin的數量。

我正在嘗試此操作,但它無法在nclass中正確讀取三個不同的bin大小。 我究竟做錯了什么?

plot.historgrams <- function(x,nclass, ...){
  for (i in 1:length(nclass)) {
  hist(x,nclass=nclass[i], ...)
  }
}

plot.histograms(hidalgo.dat[,1], c(12,36,60), main="1872 Hidalgo 
   issue",xlab= "Thickness (mm)")

當我使用break並將x =放在數據集前面時,它似乎正在工作。

plot.historgrams <- function(x,b, ...){
  for (i in 1:length(b)){
  hist(x=x,breaks=b[i], ylab=paste("Frequency, bins= ",b[i]),  ...)
  }
}

plot.historgrams(x=hidalgo.dat[,1], c(12,36,60), main="1872 Hidalgo issue",xlab= "Thickness (mm)")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM