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

HW-02 Daniel Sanchez #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DJCSanchez
Copy link

No description provided.

@DJCSanchez DJCSanchez changed the title COMMITTTTTT HW-02 Daniel Sanchez Jul 14, 2020
Copy link

@maryefrith maryefrith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer review part 1


After some digging, looked in the "element_text()" function. I saw angle, I played with lineheight (my answer from an initial google, but values of -3, 0, 7 in lineheight provided no changes in the car names in the graph). Then I tried hjust and used 1 as my first guess.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option for avoiding the overlap of the x axis labels with the plot is to add a margin, for example: theme(axis.text.x = element_text(margin = margin(15, 0, 0, 0)))
The numbers inside "margin()" refer to the spaces to the top, right, bottom, and left of the text. The default unit for these numbers is "pt" (?) but if you want a different unit size you can specify it as the fifth argument (e.g., margin(1, 1, 1, 1, "cm").

@@ -92,6 +102,7 @@ Now using the above mpg dataset, make this graph

```{r graph 4 code}

ggplot(mpg, aes(x = cty , y = class, color = class)) + geom_jitter(width = 0.2) + geom_boxplot(color = "black", outlier.shape = NA) + labs(x= "City mpg" , y = "Car Class", title = "Horizontal BoxPlot of City MPG and Car Class") + scale_color_brewer(palette= "Set2")
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solid job! I didn't get this far in the graphs, so way to go. Check plus

Copy link

@maryefrith maryefrith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer review part 2

```

I may have taken the easy way out. I tried to look online on how to specify. I thought I had figured out it by specifying aesthetic command in geom_smooth (I had written, geom_smooth(aes(x = displ, y = hwy)) thinking that it would plot against only those coordinates. but to no avail). The last resot option I could think of was to eliminate the color assignment, and now only one line is present. -DS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, what you did worked to get just the single line! If you want to keep the different colors in the graph and also do just one line, then this is what worked for me:
mpg %>%
ggplot(mapping = aes(x = displ, y = hwy)) +
geom_point(aes(color = drv)) +
geom_smooth(se = F)

In other words, I moved the color argument into geom_point so that geom_smooth doesn't also include it (which it did when color was mapped to drv at the top of the ggplot function).

```


Using the diamonds dataset, make this graph:
```{r graph1 code, echo=FALSE}


ggplot(diamonds, aes(x = cut, color = clarity, fill = clarity)) +geom_bar(position = 'dodge') + labs(x = "Diamond Cut" , y = "Number of Diamonds")
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! You got the x and y labels, color, bar positions, axes, etc., to match that of the mimic graph. You forgot the plot title and subtitle though! Here is what I did for that:

ggtitle("My Diamond Collection", subtitle = "Boxplot representing the number of diamonds in my diamond collection by\ntype of cut quality and clarity of diamond") +
theme(plot.title = element_text(hjust = 0.5))

The \n (in the subtitle) serves as a line break. I'm not sure if there is a way to make the subtitle automatically wrap at the desired point without specifying exactly where the line break should be.
I "centered" the title using the theme function and hjust = 0.5 (half way across the top of the graph).

theme(axis.text.x = element_text(angle = 45))
v <- ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, color = manufacturer, fill = manufacturer)) +
geom_boxplot() + theme(axis.text.x = element_text(angle = 45)) + theme(axis.text.x = element_text(hjust = 1))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, your graph is making me realize now that I might have misinterpreted the color question:
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?
I made all of the boxes the same color (black), rather than multiple colors... so kudos to you for making the boxes each uniformly one color rather than making all the box outlines the same color like I did.


##Removing the plot legend
## q + theme(legend.position = 'none')
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you assigned the plots to a letter so that you didn't have to include another block of repetitive code (...like I did) when answering the different question prompts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants