Please enable JavaScript.
Coggle requires JavaScript to display documents.
TAE Week 1 - Coggle Diagram
TAE Week 1
R Revision
-
-
tapply(x, index, function)
table() provides a count of the different factors in the column
- can be two columns - table(df$x, df$y) but how you read this will be the vertical axis of the table will be the df$x and the horizontal axis of the table will be df$y
-
max(table(x,y)) will show the maximum number of things that have the exact same value for both variables
-
indexing a dataframe - df [ row , column]
R Visualisation
-
ggplot
facet_grid(z~.) vs facet_grid(.~z) - one is row stacked on top of each other, while the other is columns next to each other
geom_histogram(binwidth) refers to the number on the xaxis (so binwidth = 30 years if x axis is age)
geom_histogram(closed = left/right) means whether you want to include the left/right inside the counting
legend and labelling:
- labs(fill = "Title of Legend")
- use fill in aes command to separate and legend and their corresponding names will auto appear
- scale_fill_discrete(labels = c("x", "y")) if you want to change the name of the legend categories
-
geom_histogram things:
- position = "identity" means that the bars will not be stacked
- alpha = 0.5 will change the transparency
- hist(will draw a nicer histogram more easily)