Week 16- R studio Flashcards
What is the as.factor function and how do you use it?
When you want to convert the data type of a variable to a factor/categorical variable.
studytwo$ETHNICITY <- as.factor(studytwo$ETHNICITY)
summary(studytwo)
How to see an overview of the data
head(studytwo)
summary(studytwo)
How do you do a histogram (using a ggplot)
ggplot(data = studytwo, aes(x = mean.acc)) + geom_histogram()
What is a binwidth and how do you add it onto a calculation?
We adjust binwidth typically to improve the appearance of the plot.
ggplot(data = studytwo, aes(x = SHIPLEY)) + geom_histogram(binwidth = 0.1)
How to edit the colour of histogram theme?
ggplot(data = studytwo, aes(x = SHIPLEY)) +
geom_histogram(binwidth = 0.5) +
theme_bw()
How to edit the labels of the histogram
ggplot(data = studytwo, aes(x = SHIPLEY)) +
geom_histogram(binwidth = 0.5) +
theme_bw() +
labs(x = “SHIPLEY”, y = “number of”)
How do you create a scatterplot examining the association between variables?
ggplot(data = studytwo, aes(x = SHIPLEY, y = HLVA)) +
geom_point()
How to change the appearance of a ggplot- alpha, size, colour, theme, labels
ggplot(data = studytwo, aes(x = HLVA, y = mean.self)) +
geom_point(alpha = 0.5, size = 2, colour = purple) +
theme_bw() +
labs(x = “HLVA”, y = “mean self rated accuracy”)
How would you code a correlation test?
cor.test(studytwo$HLVA, studytwo$mean.acc, method = “pearson”, alternative = “two.sided”)