Skip to content
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

Johnathon Hall - HW02 #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
Binary file added CityMPGvsCarClass_Plot.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 Corvette_plot.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 Diaomonds_Plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 15 additions & 13 deletions HW02_A_Graph-Fails.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ 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()

```

### 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"))
mpg %>%
ggplot(mapping = aes(x = displ, y = hwy)) +
geom_point(color = 'blue')

```

Expand All @@ -55,9 +56,12 @@ 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.title = element_blank())
theme(legend.direction = "horizontal") +
theme(legend.position = c(5, 40))
theme(legend.position = c(.714, .8))

#to remove the legend, use: theme(legend.position='none')

```

Expand All @@ -66,8 +70,8 @@ I wanted just one smoothing line. Just one line, to show the general relationshi

```{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
```

Expand All @@ -79,9 +83,7 @@ Also, the x-axis labels were overlaping, so I rotated them. But now they overlap

```{r}
ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, color = manufacturer)) +
geom_boxplot() +
theme(axis.text.x = element_text(angle = 45))
```



geom_boxplot(aes(fill = manufacturer, alpha =0.1)) +
theme(axis.text.x = element_text(angle = 45)) +
theme(axis.text.x = element_text(margin = margin(t = 20)))
```
30 changes: 30 additions & 0 deletions HW02_B_Mimic.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ is for. :smile:
``` r
data("diamonds")
#hint think about the *position* the bars are in...

ggplot(diamonds, aes(x = cut, fill = clarity)) +
geom_bar(position = "dodge") +
labs(title = "My Diamond Collection", subtitle = "Boxplot representing the number of diamonds in my diamond collection by type of cut quality and clarity of diamond", x = "Diamond Cut", y = "Number of Diamonds") +
annotate(
"text",
x = 4, y = 5000,
label = "My Best Diamonds, of course",
vjust = 1, size = 3
)

```

Using the diamonds dataset, make this graph:
Expand All @@ -46,6 +57,11 @@ data("iris")
Using the iris dataset, make this graph:

## `geom_smooth()` using formula 'y ~ x'

ggplot(iris, aes(Sepal.Length, Petal.Length)) +
geom_point(aes(shape = factor(Species), color = factor(Species))) +
facet_wrap("Species") +
geom_smooth(formula = y ~ x)

![](HW02_B_Mimic_files/figure-gfm/unnamed-chunk-4-1.png)<!-- -->

Expand All @@ -69,6 +85,12 @@ There is a trick to getting the model and year to print off together.
`paste()` is a useful function for this, also pasting together parts of
file names and parts of urls together.

ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_point(data = corvette, color = "red") +
geom_text(data = corvette, aes(label = paste(model, year), hjust = 1.1)) +
labs(title = "Corvettes are a bit of an outlier")

### Graph 4

``` r
Expand All @@ -87,3 +109,11 @@ graph below, I used Set2.
Now using the above mpg dataset, make this graph

![](HW02_B_Mimic_files/figure-gfm/unnamed-chunk-8-1.png)<!-- -->

ggplot(mpg, aes(class, cty, color = class)) +
geom_boxplot() +
geom_jitter() +
coord_flip() +
scale_color_brewer(palette="Set2") +
labs(title = "Horizontal Boxplot of City MPG and Car Class", y = "City MPG", x = "Car Class")

13 changes: 13 additions & 0 deletions Homework2.Rproj
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
Binary file added Iris_Plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ There are two parts to the HW this week.

[The first assignment asks you to fix some common issues with making ggplot plots ](HW02_A_Graph-Fails.Rmd). You can find the code in that link or the file: HW02_A_Graph-Fails.Rmd

#I have attempted to fix the code in HW02_A_Graph_Fails.Rmd

The second part of the HW will likely be more challenging as it asks you to try to recreate the graphs from just the images. [Here is a link to the markdown file](HW02_B_Mimic.md) with the images you will try to recreate or you can just find the file "HW02_B_Mimic.md" or find the html version "HW02_B_Mimic.html" (which would need to be previewed in RStudio or opened up by an internet browser to view properlY) in the repo. To make your lives easier, I also created a "starter" document that has the same code that you can find in the markdown (but obviously the code for the graphs themselves was removed). [Here is a link to the starter document](HW02_B_Mimic_starter.Rmd) or you can look for the file "HW02_B_Mimic_starter.Rmd"

#I have written code for the graphs in HW02_B_Mimic.md
#My PNG files should be included in this directory for the graphs.

#Thanks for stopping by!