ggplot2 Bar Chart – Simple to Powerful Themes with Kaggle Notebook

[This article was first published on r-bloggers on Programming with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In this R tutorial, We’ll learn the following tips and tricks of ggplot2 bar chart

  • Create a new R Notebook from Kaggle Dataset
  • Clean Column names with Janitor
  • How Make a Ggplot2 Bar Chart (Column Chart) in R
  • Why use geom_col instead of geom_bar
  • How to flip the coordinates of ggplot Bar charts
  • How to reorder the Bars in Ggplot Bar Chart
  • How to add Labels to a ggplot bar chart
  • How to make a beautiful ggplot2 bar chart from Basic to Powerful Themes using ggthemes

Video Tutorial on ggplot2 Bar Chart Themes

Final Code – Economist Theme

state_2018 %>%
    select(one_of('state_ut','total_victims')) %>%
    arrange(desc(total_victims)) %>%
    head(20) %>%
    mutate(state_ut = fct_reorder(state_ut,total_victims)) %>%
    ggplot() + geom_col(aes(y = state_ut,x =total_victims), fill = 'red') +
    geom_label(aes(y = state_ut,x =total_victims, label = total_victims), fill = 'yellow')+
    labs(title = '2018 Rape Victims in India - Top 20 states',
        subtitle = 'by Total Victim Count',
        caption = 'Data Source: Kaggle / Crimes in India') +
#theme_hc(style = 'darkunica') +
theme_economist() +
theme(axis.text.x = element_text(color = 'red'),
     axis.text.y = element_text(color = 'red'))

Kaggle Notebook – Complete Code

Crime in India – ggplot2 Bar Chart Evolution

To leave a comment for the author, please follow the link and comment on their blog: r-bloggers on Programming with R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)