[英]Is there an R function to adjust scale in the axis for a barchart?
我有一個名為 crashes_deaths_injuries_TA_pop 的 dataframe,它看起來像:
TA_name | 人口 |
---|---|
血塊 | 34466 |
布勒 | 444444 |
克魯斯 | 34455 |
我試圖用條形圖顯示數據,但是 x 軸的比例混亂了,我不知道該怎么做。 我知道這一定很容易,但我是編碼新手,所以我很掙扎。
這是我的條形圖代碼:
ggplot(crashes_deaths_injuries_TA_pop, aes(x = reorder(TA_name, Population), y = Population, fill = Population)) +
geom_col(alpha = 0.7) +
scale_fill_distiller(palette = "Reds", direction = 1) +
coord_flip() +
labs(x = "", y = "Population", fill = "Population",
title = "Populations of South Island TA's | 2018",
caption = "Data: Census 2018, StatsNZ") +
theme_minimal() +
theme(legend.position = "none")
我還想知道如何在每個 TA_name 的每個欄的末尾添加像人口一樣的數字
使用scale_y_continuous(breaks = )
編輯您的 x 軸刻度,並使用geom_text
在條形圖旁邊添加Population
。 這是一個例子。
ggplot(crashes_deaths_injuries_TA_pop, aes(x = reorder(TA_name, Population), y = Population, fill = Population)) +
geom_col(alpha = 0.7) +
scale_fill_distiller(palette = "Reds", direction = 1) +
coord_flip() +
labs(x = "", y = "Population", fill = "Population",
title = "Populations of South Island TA's | 2018",
caption = "Data: Census 2018, StatsNZ") +
theme_minimal() +
theme(legend.position = "none") +
scale_y_continuous(breaks = seq(0, 5e05, 0.5e05)) + geom_text(aes(label = Population, y = Population+0.18e05))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.