scu*_*fer 2 r bar-chart ggplot2
我有一个名为 crashes_deaths_injuries_TA_pop 的数据框,如下所示:
| TA_姓名 | 人口 |
|---|---|
| 血块 | 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")
Run Code Online (Sandbox Code Playgroud)
我还想知道如何在每个 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))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
234 次 |
| 最近记录: |