1
我想對部分數據進行直方圖放大。我的問題是,我想剔除範圍之外的所有內容,並將其歸入最後一類「10+」。使用ggplot2可以做到嗎?使用ggplot2在直方圖中對數據進行極限分組
示例代碼:
x <- data.frame(runif(10000, 0, 15))
ggplot(x, aes(runif.10000..0..15.)) +
geom_histogram(aes(y = (..count..)/sum(..count..)), colour = "grey50", binwidth = 1) +
scale_y_continuous(labels = percent) +
coord_cartesian(xlim=c(0, 10)) +
scale_x_continuous(breaks = 0:10)
這裏是直方圖現在的樣子: How the histogram looks now
這裏是我怎麼想它看起來: How the histogram should look
也許這是不可能性,以通過嵌套ifelses來做到這一點,但正如我在我的問題中,更多的情況下ggplot可以做到這一點嗎?
通常的策略與ggplot2是要更改數據,如果你想要這種類型的變化。因此,例如,您可以創建一個具有「10+」類別的變量,其中此bin中的所有值都在此處。然後繪圖很簡單。 (還有,「搶答」?你的意思是「分組」?) – RobertMc
哦!抱歉我的拼寫錯誤! –
沒問題!我只是想確保它不是別的:-) – RobertMc