Assignment 3
Preparation
Download this Rmarkdown file, fill in your name and student number, and complete your assignment in the Rmarkdown file. “knit” your text and code into a pdf-file, and upload this pdf-file on Brightspace before the next lecture.
Visualization A
For this visualization we’re using some data from the General Social Survey data (2016). Here you can find more information from this dataset: https://rdrr.io/github/kjhealy/socviz/man/gss_sm.html
Packages
library(ggplot2)
library(socviz) # install.packages("socviz") if you haven't done so
data <- gss_sm # gss_sm is a dataset from the package socviz
data
## # A tibble: 2,867 × 32
## year id ballot age childs sibs degree race sex region income16
## <dbl> <dbl> <labelled> <dbl> <dbl> <labe> <fct> <fct> <fct> <fct> <fct>
## 1 2016 1 1 47 3 2 Bache… White Male New E… $170000…
## 2 2016 2 2 61 0 3 High … White Male New E… $50000 …
## 3 2016 3 3 72 2 3 Bache… White Male New E… $75000 …
## 4 2016 4 1 43 4 3 High … White Fema… New E… $170000…
## 5 2016 5 3 55 2 2 Gradu… White Fema… New E… $170000…
## 6 2016 6 2 53 2 2 Junio… White Fema… New E… $60000 …
## 7 2016 7 1 50 2 2 High … White Male New E… $170000…
## 8 2016 8 3 23 3 6 High … Other Fema… Middl… $30000 …
## 9 2016 9 1 45 3 5 High … Black Male Middl… $60000 …
## 10 2016 10 3 71 4 1 Junio… White Male Middl… $60000 …
## # ℹ 2,857 more rows
## # ℹ 21 more variables: relig <fct>, marital <fct>, padeg <fct>, madeg <fct>,
## # partyid <fct>, polviews <fct>, happy <fct>, partners <fct>, grass <fct>,
## # zodiac <fct>, pres12 <labelled>, wtssall <dbl>, income_rc <fct>,
## # agegrp <fct>, ageq <fct>, siblings <fct>, kids <fct>, religion <fct>,
## # bigregion <fct>, partners_rc <fct>, obama <dbl>
Your task
On the basis of data from General Social Survey, try to create an informative and pretty graph. Include the following elements.
On the x-axis, use the number of siblings. However, using
case_when
, make a new variable that recodes thesibs
variable into a new variablesibs_rec
, such that the following categories exist: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10+. Thus the important point is that people with equal to or more than 10 siblings are categorised into one category, “10+”. On the y-axis use the average number of children the respondent has for each categorie on the x-axis.Multiple layers are encouraged. Error bars would also be neat.
Explain in no more than 250 words what the graph is showing, and what unique insights it delivers. Also reflect on what it fails to show or what you would have liked to include in the graph but was not able to.
Create appropriate axis-labels and titles.
Create your own theme and add this theme to your graph.
Be sure to create clean code (see here)
Visualization B
For this visualization we’re using the gapminder
dataset again.
Packages
On the basis of the gapminder data, try to create an informative and pretty graph. Include the following elements.
Create a lineplot for all Asian countries for the GDP (
gdpPercap
) across time.One line shows a remarkable decrease in GDP over time. Try and find a way to give this line a different colour.
Create appropriate axis-labels and titles.
Create your own theme and add this theme to your graph.
Be sure to create clean code (see here)
Submit your PDF-file online
When you are done with your assignment, try clicking the “Knit”-button in Rstudio so that your code will be knitted into a pdf-file. Submit this file on Brightspace.
If you see an error appear, try to fix the error and try again. If you can’t get the “knitting” to work, then you can copy your code, text, and graphs into a word-file and submit it on Brightspace.