-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viola Nawrocka - Homework 2 #49
Open
violecule
wants to merge
16
commits into
CFBSD-Summer2020:master
Choose a base branch
from
violecule:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
354b6de
New project
6fac551
Graph fix
3e2e67e
Saving
54a3f3a
Saving
25ec65c
Graph #1 almost finished
8e30478
Graph #1 - done
123e750
Graph #1 - done
429cf13
Graph #2 - almost done
14be64a
Graph #3 - done
649fe69
Graph #4 - done
382b70a
...
b63e950
Final version
632b202
Graph fix - trying to load plots
fa98771
Adding visible plots to my Md file
c143d8b
Adding links to part A and part B
743acd7
Fixing the header for Graph 4
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: "What went wrong?" | ||
author: "Robert Gruener" | ||
date due: "7/13/2020" | ||
output: github_document | ||
--- | ||
|
||
```{r setup, include=TRUE} | ||
knitr::opts_chunk$set(echo = TRUE, error = TRUE) | ||
``` | ||
|
||
## HW02 Part A | ||
|
||
In this document, I will add some examples of some coding mistakes, it is up to you to figure out why the graphs are messing up. | ||
|
||
### First load packages | ||
|
||
It is always best to load the packages you need at the top of a script. It's another common coding formatting standard (like using the assignment operator instead of the equals sign). In this case, it helps people realize what they need to install for the script and gives an idea of what functions will be called. | ||
|
||
It is also best coding practice to only call the packages you use, so if you use a package but end up tossing the code you use for it, then make sure to remove loading it in the first place. For example, I could use `library("tidyverse")` but since this script will only be using ggplot2, I only load ggplot2. | ||
|
||
```{r load libraries} | ||
library("ggplot2") | ||
library("magrittr") #so I can do some piping | ||
``` | ||
|
||
|
||
### Graph Fix 1 | ||
|
||
What error is being thrown? How do you correct it? (hint, the error message tells you) | ||
|
||
```{r} | ||
data(mpg) #this is a dataset from the ggplot2 package | ||
|
||
#the column was actually called "cty", not "city" | ||
mpg %>% | ||
ggplot(mapping = aes(x = cty, y = hwy, color = "blue")) + | ||
geom_point() | ||
|
||
``` | ||
|
||
### Graph Fix 2 | ||
Why aren't the points blue? It is making me blue that the points in the graph aren't blue :`( | ||
```{r} | ||
ggplot(data = mpg) + | ||
geom_point(mapping = aes(x = displ, y = hwy), color = "blue") | ||
|
||
``` | ||
|
||
|
||
|
||
### Graph Fix 3 | ||
Two mistakes in this graph. First, I wanted to make the the points slightly bolder, but changing the alpha to 2 does nothing. What does alpha do and what does setting it to 2 do? What could be done instead if I want the points slightly bigger? | ||
|
||
Second, I wanted to move the legend on top of the graph since there aren't any points there, putting it at approximately the point/ordered pair (5, 40). How do you actually do this? Also, how do you remove the legend title ("class")? Finally, how would you remove the plot legend completely? | ||
```{r} | ||
mpg %>% | ||
ggplot() + | ||
#Alpha controls transparency; since max value for this parameter is 1, 2 doesn't change anything. | ||
#Instead of alpha = 2, use size = 2 to make the points bigger. | ||
|
||
geom_point(mapping = aes(x = displ, y = hwy, color = class), size = 2) + | ||
theme(legend.direction = "horizontal") + | ||
theme(legend.position = c(0.6, 0.8)) + | ||
theme(legend.title = element_blank()) | ||
|
||
``` | ||
|
||
### Graph Fix 4 | ||
I wanted just one smoothing line. Just one line, to show the general relationship here. But that's not happening. Instead I'm getting 3 lines, why and fix it please? | ||
|
||
```{r} | ||
mpg %>% | ||
ggplot(mapping = aes(x = displ, y = hwy, color=drv)) + | ||
geom_point() + | ||
|
||
#Needed to change the data considered for geom_smooth to hwy vs. displ only, and eliminate the drv. | ||
|
||
geom_smooth(aes(x = displ, y = hwy, color=NULL), se = F) | ||
#se = F makes it so it won't show the error in the line of fit | ||
|
||
``` | ||
|
||
### Graph Fix 5 | ||
I got tired of the points, so I went to boxplots instead. However, I wanted the boxes to be all one color, but setting the color aesthetic just changed the outline? How can I make the box one color, not just the outline? | ||
|
||
Also, the x-axis labels were overlaping, so I rotated them. But now they overlap the bottom of the graph. How can I fix this so axis labels aren't on the graph? | ||
|
||
|
||
```{r} | ||
ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, fill = manufacturer, color = manufacturer)) + | ||
geom_boxplot() + | ||
theme(axis.text.x = element_text(angle = 45, vjust=1, hjust=1)) | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
What went wrong? | ||
================ | ||
Robert Gruener | ||
|
||
``` r | ||
knitr::opts_chunk$set(echo = TRUE, error = TRUE) | ||
``` | ||
|
||
## HW02 Part A | ||
|
||
In this document, I will add some examples of some coding mistakes, it | ||
is up to you to figure out why the graphs are messing up. | ||
|
||
### First load packages | ||
|
||
It is always best to load the packages you need at the top of a script. | ||
It’s another common coding formatting standard (like using the | ||
assignment operator instead of the equals sign). In this case, it helps | ||
people realize what they need to install for the script and gives an | ||
idea of what functions will be called. | ||
|
||
It is also best coding practice to only call the packages you use, so if | ||
you use a package but end up tossing the code you use for it, then make | ||
sure to remove loading it in the first place. For example, I could use | ||
`library("tidyverse")` but since this script will only be using ggplot2, | ||
I only load ggplot2. | ||
|
||
``` r | ||
library("ggplot2") | ||
library("magrittr") #so I can do some piping | ||
``` | ||
|
||
### Graph Fix 1 | ||
|
||
What error is being thrown? How do you correct it? (hint, the error | ||
message tells you) | ||
|
||
``` r | ||
data(mpg) #this is a dataset from the ggplot2 package | ||
|
||
#the column was actually called "cty", not "city" | ||
mpg %>% | ||
ggplot(mapping = aes(x = cty, y = hwy, color = "blue")) + | ||
geom_point() | ||
``` | ||
|
||
![](HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-1-1.png)<!-- --> | ||
|
||
### Graph Fix 2 | ||
|
||
Why aren’t the points blue? It is making me blue that the points in the | ||
graph aren’t blue :\`( | ||
|
||
``` r | ||
ggplot(data = mpg) + | ||
geom_point(mapping = aes(x = displ, y = hwy), color = "blue") | ||
``` | ||
|
||
![](HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-2-1.png)<!-- --> | ||
|
||
### Graph Fix 3 | ||
|
||
Two mistakes in this graph. First, I wanted to make the the points | ||
slightly bolder, but changing the alpha to 2 does nothing. What does | ||
alpha do and what does setting it to 2 do? What could be done instead if | ||
I want the points slightly bigger? | ||
|
||
Second, I wanted to move the legend on top of the graph since there | ||
aren’t any points there, putting it at approximately the point/ordered | ||
pair (5, 40). How do you actually do this? Also, how do you remove the | ||
legend title (“class”)? Finally, how would you remove the plot legend | ||
completely? | ||
|
||
``` r | ||
mpg %>% | ||
ggplot() + | ||
#Alpha controls transparency; since max value for this parameter is 1, 2 doesn't change anything. | ||
#Instead of alpha = 2, use size = 2 to make the points bigger. | ||
|
||
geom_point(mapping = aes(x = displ, y = hwy, color = class), size = 2) + | ||
theme(legend.direction = "horizontal") + | ||
theme(legend.position = c(0.6, 0.8)) + | ||
theme(legend.title = element_blank()) | ||
``` | ||
|
||
![](HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-3-1.png)<!-- --> | ||
|
||
### Graph Fix 4 | ||
|
||
I wanted just one smoothing line. Just one line, to show the general | ||
relationship here. But that’s not happening. Instead I’m getting 3 | ||
lines, why and fix it please? | ||
|
||
``` r | ||
mpg %>% | ||
ggplot(mapping = aes(x = displ, y = hwy, color=drv)) + | ||
geom_point() + | ||
|
||
#Needed to change the data considered for geom_smooth to hwy vs. displ only, and eliminate the drv. | ||
|
||
geom_smooth(aes(x = displ, y = hwy, color=NULL), se = F) | ||
``` | ||
|
||
## `geom_smooth()` using method = 'loess' and formula 'y ~ x' | ||
|
||
![](HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-4-1.png)<!-- --> | ||
|
||
``` r | ||
#se = F makes it so it won't show the error in the line of fit | ||
``` | ||
|
||
### Graph Fix 5 | ||
|
||
I got tired of the points, so I went to boxplots instead. However, I | ||
wanted the boxes to be all one color, but setting the color aesthetic | ||
just changed the outline? How can I make the box one color, not just the | ||
outline? | ||
|
||
Also, the x-axis labels were overlaping, so I rotated them. But now they | ||
overlap the bottom of the graph. How can I fix this so axis labels | ||
aren’t on the graph? | ||
|
||
``` r | ||
ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, fill = manufacturer, color = manufacturer)) + | ||
geom_boxplot() + | ||
theme(axis.text.x = element_text(angle = 45, vjust=1, hjust=1)) | ||
``` | ||
|
||
![](HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-5-1.png)<!-- --> |
Binary file added
BIN
+28.4 KB
HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.1 KB
HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.9 KB
HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.3 KB
HW02_A_Graph-Fails---Viola-fix_files/figure-gfm/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the graphs now! I have to go to the top right corner of this file with the "...", click the dots and then say "see file" and it brings me to a github page with the graphs on them. Nice job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thank you for pointing it out. It makes it much easier to review!