Welcome to your first graphics challenge! Follow these instructions, step by step, to produce the intended graphic. We will continue to build on this, getting more and more advanced as the semester goes on.
We are going to start by getting your system set up to create your code for the semester. You will be working from this single file, all semester long! This will allow you to keep it for use in the future.
If you have not previously done so, go to this webpage and download R: http://cran.r-project.org/
Then go to this webpage and download Rstudio: http://www.rstudio.com/products/RStuido
Once you have done this, open RStudio.
Here are some helpful resources in aiding you to understand R Markdown.
Video Tutorial: https://rmarkdown.rstudio.com/authoring_quick_tour.html
Help Page: https://rmarkdown.rstudio.com/lesson-15.HTML
Here is a PDF version that I find really helpful! https://posit.co/wp-content/uploads/2022/10/rmarkdown-1.pdf
#Run the following code in your console (directly in the code running area) to download the package that allows you to create R markdown files. This code will download the package if you do not have it, and skip the download if you have already done so previously.
if (!require("rmarkdown")) {
install.packages("rmarkdown", dependencies = TRUE)
library(rmarkdown)
}
if (!require("knitr")) {
install.packages("knitr")
library(knitr)
}
if (!require("tinytex")) {
install.packages("tinytex")
library(tinytex)
tinytex::install_tinytex() # Install TinyTeX distribution
}
Replace the “Untitled1” title with “YOURLASTNAME Data Visualization Code”.
Click the little disk to save the file, and name it the same thing. Be very selective of where you save the file, as all of your data will need to be stored in the same location. I recommend creating a folder on your desktop for this course, saving this file there, and exclusively using that folder moving forward. And remember to save your work often.
Place the following code in the file right under the header, but remove the leading hash tags. I have to put those in for the code to display to you. Any code that you write has to go between these two lines, or it will not run or display to me. Anything you write outside of this is interpreted as plain text instead of code. This means that outside of this region, you can write notes, or write me messages just like you would in a word document. You do not need hashtags. It can allow you to keep really neat files (see the help PDF for organization tricks).
#```{r,message=F, warning=FALSE}
#```
# List any packages you need to use here
packages <- c("ggplot2", "readr", "tidyverse", "dplyr", "ggpubr")
#Check to see if any of your listed packages need installed
check_install_packages <- function(pkg){
if (!require(pkg, character.only = TRUE)) {
install.packages(pkg, dependencies = TRUE)
library(pkg, character.only = TRUE)
}
}
# Download the packages and read in the libraries if necessary
sapply(packages, check_install_packages)
Import your data for today’s activity by using a demo data set
called “USArrests”. Use your text to figure this out. Remember, you can
start with data("")
.
Look at the data, and in the “open text” space of this R Markdown document, write a description of the variables you see. You can type this out just as you would in a word document. Hint: Use the head function to see the data, and the ? function to learn more about it. Be sure to answer:
#General format is going to be calling a ggplot, followed by the dataframe name (mtcars), followed by defining the X and Y variables of the graphic.
ggplot(mtcars, aes(x = mpg, y=hp)) +
#You then indicate the type of graph to make (in this case, a dotplot using points).
geom_point()
- These are the absolute basics of a ggplot. You have to tell
it what data to use, what variables to choose, and what type of graph to
make.
scale_color_manual
code.If you have done it correctly, you should get this graphic!
Use any other demo data set to create another graph. You have full freedom to create anything you’d like! Explore other graph types and aesthetic options!
You are now ready to save the assignment to your own webpage! Let me walk you through that. This is how you will be turning in your projects this semester.
Graphics Assignment 2: {.tabset .tabset-fade}