gpt4 book ai didi

r - 是否有 R 函数可以调整条形图轴的比例?

转载 作者:行者123 更新时间:2023-12-02 01:57:22 26 4
gpt4 key购买 nike

我有一个名为 crashes_deaths_injuries_TA_pop 的数据框,如下所示:

<表类=“s-表”><标题>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 的每个栏末尾添加人口作为数字

bar chart

最佳答案

使用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))

enter image description here

关于r - 是否有 R 函数可以调整条形图轴的比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69475063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com