我想繪製以下數據集的直方圖。這gistograms應該爲每個獨特的組在該組中總生育條對母親的年齡和相應的罪名:我想用ggplot繪製直方圖ggplot審美aes()返回錯誤stat_bin()
mother_age birth_count
25 - 29 2
30 - 34 1
35 - 39 2
40 - 44 2
20 - 24 2
25 - 29 7
30 - 34 13
35 - 39 5
40 - 44 1
15 - 19 5
20 - 24 8
25 - 29 25
30 - 34 46
35 - 39 31
40 - 44 6
15 - 19 16
20 - 24 48
25 - 29 162
30 - 34 212
35 - 39 100
40 - 44 22
15 - 19 7
20 - 24 63
25 - 29 162
30 - 34 237
35 - 39 128
40 - 44 20
15 - 19 1
20 - 24 15
25 - 29 48
:
df1$mother_age <- as.factor(df1$mother_age)
df1$birth_count <- as.numeric(df1$birth_count)
mthr_chld <- ggplot(df1, aes(x=mother_age, y=birth_count)) +
ggtitle ("Mother Children") +
geom_histogram() +
labs(x = 'Mother\'s Age Group', y = 'Total Births')
mthr_chld
它拋出一個錯誤:
Error: stat_bin() must not be used with a y aesthetic.
我在哪裏犯錯?
d ata已經裝箱了,所以只需用'geom_bar'製作一個條形圖即可。你需要確保'mother_age_group'的因子級別也是有序的。 – alistaire
'ggplot(df1,aes(mother_age,birth_count))+ geom_bar(stat ='identity')' – ahly
@ahly非常感謝。讓我嘗試一下。 –