2016-12-23 44 views
0

我有一個df,我tryint與geom_histogram功能繪製:GGPLOT2錯誤「警告:忽略未知參數:箱」

structure(list(dFormat = c("11M 50S", "13M 30S", "14M 20S", "14M 40S", 
"1M 10S", "1M 20S", "1M 40S", "1M 50S", "2M 10S", "2M 20S", "2M 30S", 
"2M 40S", "2M 50S", "3M 0S", "3M 10S", "3M 20S", "3M 30S", "3M 40S", 
"3M 50S", "4M 0S", "4M 10S", "4M 20S", "4M 30S", "4M 40S", "4M 50S", 
"5M 0S", "5M 10S", "5M 20S", "5M 30S", "5M 40S", "5M 50S", "6M 0S", 
"6M 10S", "6M 20S", "6M 30S", "6M 40S", "6M 50S", "7M 0S", "7M 10S", 
"7M 20S", "7M 30S", "7M 40S", "7M 50S", "8M 0S", "8M 10S", "8M 20S", 
"8M 30S", "8M 40S", "8M 50S", "9M 0S", "9M 10S", "9M 20S", "9M 30S" 
), freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
2L, 6L, 7L, 10L, 20L, 22L, 47L, 39L, 82L, 66L, 121L, 107L, 162L, 
145L, 208L, 162L, 240L, 162L, 228L, 200L, 197L, 159L, 185L, 126L, 
157L, 113L, 123L, 73L, 61L, 49L, 33L, 23L, 18L, 11L, 16L, 5L, 
6L, 4L, 2L, 2L)), .Names = c("dFormat", "freq"), row.names = c(NA, 
-53L), class = "data.frame") 

我試圖做一個簡單的柱狀圖用下面的代碼,但我得到一個錯誤:

ggplot(df, aes(x = df$dFormat, y = df$freq)) + geom_histogram(stat = "identity",binwidth = 50)

Warning: Ignoring unknown parameters: binwidth, bins, pad

縱觀文件通貨膨脹我看到:

Number of bins. Overridden by binwidth. Defaults to 30

使用binwidth不能解決問題。

geom_histogram更改爲geom_bar也沒有幫助。

In addition: Warning message: geom_bar()no longer has a binwidth parameter. Please use geom_histogram()instead.

我看到了一個類似的問題在這裏,但它是沒有用的

SO question

的也許@hadley會知道

+3

我想你想'geom_bar'而不是'geom_histogram'。並且不要在內部使用$ aes()' –

+0

您目前有一個離散x軸,這意味着histograms /'stat_bin'將不會有用。 bin和binwidth等工作在一個連續的x軸上進行頻率圖。也許澄清你的結果情節應該是什麼樣子?如果你想要結合一些x水平,你可能需要計算ggplot2以外的摘要。 – aosmith

+0

您的數據已經是統計摘要。在這種情況下,您應該使用'geom_bar'來顯示結果而不是'geom_histogram',因爲'geom_histogram'會爲您計算出頻率。對於分類變量,「binwidth」不是有用的參數。如果你真的需要使用'geom_histogram',試着讓你的'dFormat'變量連續。 – raymkchow

回答

0

我認爲理查德·特爾福德的答案已經完成。 這裏是我相信,你正在尋找:

df <- structure(list(dFormat = c("11M 50S", "13M 30S", "14M 20S", "14M 40S", 
"1M 10S", "1M 20S", "1M 40S", "1M 50S", "2M 10S", "2M 20S", "2M 30S", 
"2M 40S", "2M 50S", "3M 0S", "3M 10S", "3M 20S", "3M 30S", "3M 40S", 
"3M 50S", "4M 0S", "4M 10S", "4M 20S", "4M 30S", "4M 40S", "4M 50S", 
"5M 0S", "5M 10S", "5M 20S", "5M 30S", "5M 40S", "5M 50S", "6M 0S", 
"6M 10S", "6M 20S", "6M 30S", "6M 40S", "6M 50S", "7M 0S", "7M 10S", 
"7M 20S", "7M 30S", "7M 40S", "7M 50S", "8M 0S", "8M 10S", "8M 20S", 
"8M 30S", "8M 40S", "8M 50S", "9M 0S", "9M 10S", "9M 20S", "9M 30S" 
), freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
2L, 6L, 7L, 10L, 20L, 22L, 47L, 39L, 82L, 66L, 121L, 107L, 162L, 
145L, 208L, 162L, 240L, 162L, 228L, 200L, 197L, 159L, 185L, 126L, 
157L, 113L, 123L, 73L, 61L, 49L, 33L, 23L, 18L, 11L, 16L, 5L, 
6L, 4L, 2L, 2L)), .Names = c("dFormat", "freq"), row.names = c(NA, 
-53L), class = "data.frame") 

ggplot(df, aes(x=dFormat,y=freq))+geom_bar(stat='identity') 
+0

如果你要在'aes'(和一個代碼高爾夫球手)提供'y',你可以使用'geom_col()',它假定'stat = identity'。 –