是否有 R 函数可以调整条形图的轴比例?
Is there an R function to adjust scale in the axis for a barchart?
我有一个名为 crashes_deaths_injuries_TA_pop 的数据框,它看起来像:
TA_name
Population
Gore
34466
Buller
444444
Cluth
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))
我有一个名为 crashes_deaths_injuries_TA_pop 的数据框,它看起来像:
TA_name | Population |
---|---|
Gore | 34466 |
Buller | 444444 |
Cluth | 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))