I am in the process of working out how to create a neat table (and have never made a table at all before so just starting out!).
I am looking at the PHS open data for unintentional injuries and making a table looking at total Scotland data for 2018. I have made a table which looks ok - but I would like to create subdivision of rows to divide the results by male and female to make it look neater, as well as format the heading font size and make it a more attractive appearance. I have tried a couple of things in kableExtra but couldn't get it to work. Code below. Does anyone have any suggestions?
# Read in mortality data orig_ui_deaths = read_csv("https://www.opendata.nhs.scot/dataset/b0135993-3d8a-4f3b-afcf-e01f4d52137c/resource/89807e07-fc5f-4b5e-a077-e4cf59491139/download/ui_deaths_2020.csv")
# Create table of number of deaths by injury type, age, and sex # Pipe in orig_ui_deaths dataset orig_ui_deaths %>% # Apply filters in same was as in plots so looking at one year, whole of Scotland, and exlucing "All" entries filter(Year == "2018", HBR == "S92000003", AgeGroup != "All" & Sex != "All", InjuryType != "Accidental exposure" & InjuryType != "All")%>% # Group the table according to injury type, age, and sex group_by(InjuryType, AgeGroup, Sex) %>% # Create a summary of total number of deaths for neater appearance to the table and demonstration of the figures summarise(total_deaths = sum(NumberOfDeaths)) %>% # Change the orientation of the table so that age groups become the variable headings pivot_wider(names_from = AgeGroup, values_from = total_deaths) %>% # Create table to present the data] knitr::kable(caption = "Deaths from unintentional injuries in Scotland")