我想繪製一個數據框的一列中的值的直方圖。我嘗試設置bin或binwidth參數,但無濟於事。 R在構建情節時說:「忽略未知參數:binwidth,bin,pad」。爲什麼R會忽略ggplot geom_histogram中的binwidth,bin?
ggplot(data=subset(flights, Distance < quantile(flights$Distance, 0.75)))+ geom_histogram(aes(x=Distance), stat='count', binwidth=100)
要繪製的變量是整數,距離爲航班的載體。
我試着將數據類型從整數改爲數字。
flights$Distance <- as.numeric(as.character(flights$Distance))
我試圖在一個較小的樣本,並得到了同樣的信息。
df <- data.frame(Distance=c(2,3,4,5,3,2,4,5,6,7,5,4,9,8,7,6,5,4,3,4,5,6,5))
ggplot(data=df)+ geom_histogram(aes(x=Distance), stat='count', binwidth=2)
爲什麼ggplot忽略了兩個可能斌參數?
剛剛從調用'geom_histogram'刪除'STAT ='count''。 'geom_histogram'默認使用'stat =「bin」',這就是你想要的直方圖的屬性。 – eipi10