-
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
Ben Wang Homework 2 #31
Open
Blwang3
wants to merge
3
commits into
CFBSD-Summer2020:master
Choose a base branch
from
Blwang3: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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: "What went wrong?" | ||
author: "Robert Gruener" | ||
author: "Ben Wang" | ||
date due: "7/13/2020" | ||
output: github_document | ||
--- | ||
|
@@ -33,19 +33,19 @@ What error is being thrown? How do you correct it? (hint, the error message tell | |
data(mpg) #this is a dataset from the ggplot2 package | ||
|
||
mpg %>% | ||
ggplot(mapping = aes(x = city, y = hwy, color = "blue")) %>% | ||
ggplot(mapping = aes(x = cty, y = hwy, color = "blue")) + | ||
geom_point() | ||
|
||
``` | ||
|
||
### In the tutorial on DataCamp, we always used '+' for geom_point functions so I tried that here | ||
### I tried running the program but it could not find the object 'city'. The data refers to it as 'cty' instead of 'city', so I changed 'city' to 'cty' | ||
### Graph Fail 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")) | ||
ggplot(data = mpg, aes(x = displ, y = hwy)) + | ||
geom_point(color = "blue") | ||
|
||
``` | ||
|
||
### Need to have color separately in 'geom_point()' | ||
|
||
|
||
### Graph Fail 3 | ||
|
@@ -55,33 +55,38 @@ Second, I wanted to move the legend on top of the graph since there aren't any p | |
```{r} | ||
mpg %>% | ||
ggplot() + | ||
geom_point(mapping = aes(x = displ, y = hwy, color = class), alpha = 2) + | ||
geom_point(mapping = aes(x = displ, y = hwy, color = class), size = 2) + | ||
theme(legend.direction = "horizontal") + | ||
theme(legend.position = c(5, 40)) | ||
theme(legend.position = c(0.65, 0.85)) + | ||
theme(legend.title = element_blank()) | ||
|
||
``` | ||
### Alpha does not change the size, it changes the opacity (0 is transparent, 1 is opaque). We change 'alpha' to 'size' to set size | ||
### Experimented with different coordinates until I got the legend where I wanted it | ||
### Removing legend title wouldn't let us use "none" so "element_blank" worked instead. To completely hide the legend, I could give it a position not seen in the graph (legend.position = c(10000,10000)) or use "none". | ||
|
||
### Graph Fail 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() + | ||
ggplot(mapping = aes(x = displ, y = hwy)) + | ||
geom_point(aes(color = drv)) + | ||
geom_smooth(se = F) #se = F makes it so it won't show the error in the line of fit | ||
``` | ||
### color = drv is responsible for drawing the lines. Since it was inside ggplot(mapping), the lines were drawn indepedently of geom_point and geom_smooth layers. Placing it only in geom_point draws the line according to the point layer only, creating one line for the general relationship. | ||
|
||
### Graph Fail 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? | ||
Also, the x-axis labels were overlapping, 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, color = manufacturer)) + | ||
ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, fill = manufacturer)) + | ||
geom_boxplot() + | ||
theme(axis.text.x = element_text(angle = 45)) | ||
theme(axis.text.x = element_text(angle = 45, hjust = 1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using "hjust" is a good choice! I didn't realize I could use this command to adjust the distance so I just changed the angle to avoid overlapping lol |
||
``` | ||
|
||
|
||
### 'color' changes outline, 'fill' changes actually inside of the box | ||
### use 'hjust' to adjust horizontal axis distance | ||
|
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
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
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.
This is interesting, will there be any differences in running time between the two options?
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 didn't think of that! Using such large position may cause a longer time running or crash the program. Alternatively, if the program tries to fit everything into one space, perhaps it'll scale the the entire figure really small to accommodate for the huge distance between the figure and legend. Maybe using a different coordinate is not the best option