I have a dataframe called crashes_deaths_injuries_TA_pop that looks like:
TA_name | Population |
---|---|
Gore | 34466 |
Buller | 444444 |
Cluth | 34455 |
I am trying to show the data with a bar chart however, the scale of x-axis is messed up and I'm not sure how to . I know this must be easy but I am new to coding so I am struggling.
here is my code for the bar chart:
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")
I was also wondering how can you add like the population as a number at the end of each bar for each TA_name
CodePudding user response:
Use scale_y_continuous(breaks = )
to edit ticks of x axis of yours and use geom_text
to add Population
next to the bar chart. Here's an example.
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))