This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(forcats)
library(patchwork)
Atheletesdf <- read.csv(paste0("C:/Rdata/EntriesGender.csv"), header=TRUE, sep="|" )
Atheletesdf
## Discipline Female Male Total
## 1 3x3 Basketball 32 32 64
## 2 Archery 64 64 128
## 3 Artistic Gymnastics 98 98 196
## 4 Artistic Swimming 105 0 105
## 5 Athletics 969 1072 2041
## 6 Badminton 86 87 173
## 7 Baseball/Softball 90 144 234
## 8 Basketball 144 144 288
## 9 Beach Volleyball 48 48 96
## 10 Boxing 102 187 289
## 11 Canoe Slalom 41 41 82
## 12 Canoe Sprint 123 126 249
## 13 Cycling BMX Freestyle 10 9 19
## 14 Cycling BMX Racing 24 24 48
## 15 Cycling Mountain Bike 38 38 76
## 16 Cycling Road 70 131 201
## 17 Cycling Track 90 99 189
## 18 Diving 72 71 143
## 19 Equestrian 73 125 198
## 20 Fencing 107 108 215
## 21 Football 264 344 608
## 22 Golf 60 60 120
## 23 Handball 168 168 336
## 24 Hockey 192 192 384
## 25 Judo 192 201 393
## 26 Karate 40 42 82
## 27 Marathon Swimming 25 25 50
## 28 Modern Pentathlon 36 36 72
## 29 Rhythmic Gymnastics 96 0 96
## 30 Rowing 257 265 522
## 31 Rugby Sevens 146 151 297
## 32 Sailing 175 175 350
## 33 Shooting 178 178 356
## 34 Skateboarding 40 40 80
## 35 Sport Climbing 20 20 40
## 36 Surfing 20 20 40
## 37 Swimming 361 418 779
## 38 Table Tennis 86 86 172
## 39 Taekwondo 65 65 130
## 40 Tennis 94 97 191
## 41 Trampoline Gymnastics 16 16 32
## 42 Triathlon 55 55 110
## 43 Volleyball 144 144 288
## 44 Water Polo 122 146 268
## 45 Weightlifting 98 99 197
## 46 Wrestling 96 193 289
#creating new columns
newAtheletesdf <-Atheletesdf%>%
select(Discipline,Female,Male,Total)%>%
mutate(female_percent = Female*100/Total, male_percent = Male*100/Total)
newAtheletesdf
## Discipline Female Male Total female_percent male_percent
## 1 3x3 Basketball 32 32 64 50.00000 50.00000
## 2 Archery 64 64 128 50.00000 50.00000
## 3 Artistic Gymnastics 98 98 196 50.00000 50.00000
## 4 Artistic Swimming 105 0 105 100.00000 0.00000
## 5 Athletics 969 1072 2041 47.47673 52.52327
## 6 Badminton 86 87 173 49.71098 50.28902
## 7 Baseball/Softball 90 144 234 38.46154 61.53846
## 8 Basketball 144 144 288 50.00000 50.00000
## 9 Beach Volleyball 48 48 96 50.00000 50.00000
## 10 Boxing 102 187 289 35.29412 64.70588
## 11 Canoe Slalom 41 41 82 50.00000 50.00000
## 12 Canoe Sprint 123 126 249 49.39759 50.60241
## 13 Cycling BMX Freestyle 10 9 19 52.63158 47.36842
## 14 Cycling BMX Racing 24 24 48 50.00000 50.00000
## 15 Cycling Mountain Bike 38 38 76 50.00000 50.00000
## 16 Cycling Road 70 131 201 34.82587 65.17413
## 17 Cycling Track 90 99 189 47.61905 52.38095
## 18 Diving 72 71 143 50.34965 49.65035
## 19 Equestrian 73 125 198 36.86869 63.13131
## 20 Fencing 107 108 215 49.76744 50.23256
## 21 Football 264 344 608 43.42105 56.57895
## 22 Golf 60 60 120 50.00000 50.00000
## 23 Handball 168 168 336 50.00000 50.00000
## 24 Hockey 192 192 384 50.00000 50.00000
## 25 Judo 192 201 393 48.85496 51.14504
## 26 Karate 40 42 82 48.78049 51.21951
## 27 Marathon Swimming 25 25 50 50.00000 50.00000
## 28 Modern Pentathlon 36 36 72 50.00000 50.00000
## 29 Rhythmic Gymnastics 96 0 96 100.00000 0.00000
## 30 Rowing 257 265 522 49.23372 50.76628
## 31 Rugby Sevens 146 151 297 49.15825 50.84175
## 32 Sailing 175 175 350 50.00000 50.00000
## 33 Shooting 178 178 356 50.00000 50.00000
## 34 Skateboarding 40 40 80 50.00000 50.00000
## 35 Sport Climbing 20 20 40 50.00000 50.00000
## 36 Surfing 20 20 40 50.00000 50.00000
## 37 Swimming 361 418 779 46.34146 53.65854
## 38 Table Tennis 86 86 172 50.00000 50.00000
## 39 Taekwondo 65 65 130 50.00000 50.00000
## 40 Tennis 94 97 191 49.21466 50.78534
## 41 Trampoline Gymnastics 16 16 32 50.00000 50.00000
## 42 Triathlon 55 55 110 50.00000 50.00000
## 43 Volleyball 144 144 288 50.00000 50.00000
## 44 Water Polo 122 146 268 45.52239 54.47761
## 45 Weightlifting 98 99 197 49.74619 50.25381
## 46 Wrestling 96 193 289 33.21799 66.78201
## Group By
newAtheletesdf%>%
group_by(Discipline)
## # A tibble: 46 x 6
## # Groups: Discipline [46]
## Discipline Female Male Total female_percent male_percent
## <chr> <int> <int> <int> <dbl> <dbl>
## 1 3x3 Basketball 32 32 64 50 50
## 2 Archery 64 64 128 50 50
## 3 Artistic Gymnastics 98 98 196 50 50
## 4 Artistic Swimming 105 0 105 100 0
## 5 Athletics 969 1072 2041 47.5 52.5
## 6 Badminton 86 87 173 49.7 50.3
## 7 Baseball/Softball 90 144 234 38.5 61.5
## 8 Basketball 144 144 288 50 50
## 9 Beach Volleyball 48 48 96 50 50
## 10 Boxing 102 187 289 35.3 64.7
## # ... with 36 more rows
##Plotting and displaying plots next to each other using patch
p1 <- newAtheletesdf%>%
ggplot(aes(x = Discipline, y = female_percent)) +
geom_col(fill = "lightblue") +
labs(x = "Discipline", y = "female_percent",
caption = "https://en.wikipedia.org/wiki/Atheletesfemale_percent")
p2 <- newAtheletesdf%>%
ggplot(aes(x = Discipline, y = male_percent,male_percent)) +
geom_col(fill = "lightblue") +
labs(x = "Discipline", y = "female_percent,male_percent,",
caption = "https://en.wikipedia.org/wiki/Atheletesfemale_male_percent")
p1 + p2
## flipping coordinates
p3 <- newAtheletesdf%>%
ggplot(aes(x = Discipline, y = female_percent)) +
geom_col(fill = "lightblue") +
labs(x = "Discipline", y = "female_percent",
caption = "https://en.wikipedia.org/wiki/Atheletesfemale_percent") + coord_flip()
p4 <- newAtheletesdf%>%
ggplot(aes(x = Discipline, y = male_percent,male_percent)) +
geom_col(fill = "lightblue") +
labs(x = "Discipline", y = "female_percent,male_percent,",
caption = "https://en.wikipedia.org/wiki/Atheletesfemale_male_percent") + coord_flip()
p3 + p4
# ordered by Discipline
newAtheletesdf%>%
ggplot(aes(x = fct_reorder(Discipline,female_percent), y = female_percent)) +
geom_col(fill = "lightblue") +
labs(x = "Discipline", y = "female_percent",
caption = "https://en.wikipedia.org/wiki/Atheletesfemale_percent") + coord_flip()
```
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.