R Project - how to create bar chart (ggplot2) from spreadsheet-includes data pivot & remove a column

Published 2022-09-20
In an R script upload a spreadsheet, manipulate the data by removing column/variable, change variable name, and pivot columns, and then producing a bar chart.

Timings:
00:00 Introduction
00:40 Set up R script and load data
02:10 Remove a column/variable from the database
03:20 Change column/variable header name
04:35 Set order of category (change from default alphabetical)
07:20 Pivot using pivot_longer (tidyr package)
10:10 Set up bar chart (ggplot2 package)
13:00 Add labels to bar chart
15:10 Themes (theme()) changes to bar chart
19:00 Change colour of bars/columns.

The video mentioned at 3.10 relating to altering the number of observations/variables (rows/columns) can be found at    • In R dataframe - how to alter the num...  

There is a lot more alterations which can be done to the bar chart using ggplot2. A reference which you may find helpful - ggplot2.tidyverse.org/reference/index.html. This also explains why geom_col is used in this video, rather than geom_bar - ie it is because want height of bars to represent the values in the data.

The excel spreadsheet used in this project can be found at dataforknowledge.co.uk/r-project-create-bar-chart/

Note: 3rd party data was used in this project therefore I take no responsibility for the quality or accuracy of the data. The data can be found at www.gov.scot/publications/teacher-census-supplemen…

#rprogramming #barchart #ggplot2 #rproject #data #ggplot2barchart

All Comments (14)
  • @leanne-se2sp
    Hi, I'm in my 2nd year at university and have never been able to grasp R in any of the workshops but your video made it so easy! Thank you so much, I have been panicking about this assignment for weeks, and with your video, I can finally get it done, thank you again :) 10/10!
  • @APerson-ky2gh
    Thanks so much, I'm a second year biology student who just started learning r for ecology data stuff and this video was so helpful
  • @lucacotan4492
    Thank you so much for the video! You actually showed perfectly how to transform the excel sheet into a barplot in "R"!
  • @inamhameed4963
    Great, well-structured and organized. Much recommended your channel!!!
  • @lindalangford320
    Thanks for such an informative video. It is greatly appreciated.
  • @ibrahimlawan9663
    Column names with spaces can sometimes cause issues because R treats spaces as a special character that indicates the end of a command. To solve this, 1. you can use backticks to specify column names with spaces (e.g., ggplot(data, aes(x = `Age group`, y = Value)), 2. you can rename the column (e.g., data$Age_group <- data$`Age group`), 3. use quote (e.g., ggplot(data, aes(x = "Age group", y = Value)). I hope this will help
  • @ren.auguste2200
    Excellent video! If I may ask, do you have any for species accumulation curves? Or know where can point me in the right direction? Hoping you have one, as you explained so well!