-
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
Ariana Tortolani HW02 #13
base: master
Are you sure you want to change the base?
Conversation
A few notes / things I learned:
|
data(mpg) #this is a dataset from the ggplot2 package | ||
|
||
ggplot(mpg, aes(x = cty, y = hwy, color = "blue")) + | ||
geom_point() |
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 was what I put down for mine as well! :)
alpha = 1 : opaque | ||
alpha = 0 : transparent | ||
|
||
i am not sure what setting alpha = 2 does. i can not see any changes when i generate the plot |
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.
Based on the tutorial on DataCamp, setting the alpha = 2 should make the points appear at 20% transparency.
mpg %>% | ||
ggplot(mapping = aes(x = displ, y = hwy)) + | ||
geom_point() + | ||
geom_smooth(se = F) #se = F makes it so it won't show the error in the line of fit |
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.
Hi Ariana,
I was facing the same problem you had and I found this helpful post on stack overflow. You can refer to this link https://stackoverflow.com/questions/47883446/plot-a-single-geom-smooth-curve-instead-of-multiple or my codes for more details but essentially, there are two ways to solve this issue.
- Override the color aesthetic in geom_smooth layer
- Move the color aesthetic to only layers that need it
labs (x = "Diamond Cut", y = "Number of Diamonds") + | ||
annotate(geom = "text", x = 4, y = 4500, label = "My Best Diamonds,\nof course") + | ||
annotate("rect", xmin = 4.5, xmax = 5.5, ymin = 0, ymax = 5000, alpha = 0.25) | ||
|
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 realized when I opened your image for Graph 1, there was no black outline on the graph. I saw on Robert's example that the panel background had a black outline so in my codes, I added panel.background = element_rect(linetype = "solid", color = "black") under theme. However, I didn't see this addition in Robert's HW02 Answer Key so I am not sure how he was able to achieve the black outline or I might have missed it!
|
||
```r | ||
|
||
iris$NewOrder <- factor(iris$Species, levels = c("versicolor","setosa","virginica")) |
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.
Ahhh this is how you reorder the species. I wasn't sure how I was supposed to do this, the things I googled seemed more complicated than this. Thank you for letting me learn from you! The only problem I have left with this graph was making the lines appear smooth. I think I covered the same codes as yours and Robert but my lines are still squiggly while you guys' are so smooth! I will have to look into this more for sure.
geom_point(data = corvette, color = "blue") + | ||
geom_text_repel(data = corvette, aes(label = paste("Corvette,",year))) + | ||
scale_x_continuous(limits = c(1,8), breaks = seq(1,8,1)) + | ||
labs(title = "Corvettes are a bit of an outlier") |
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 noticed on your last blue point on the graph, there is a line that is attached to the label (Corvette, 2008). I had a similar problem - I ended up concluding that the problem was caused by the lack of space for the label to be appropriately positioned such that it appears directly associated with the point and fixed it by minimizing the font size. I am not sure if that is the best solution!
|
||
```r | ||
|
||
ggplot(mpg, aes(cty, class)) + |
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.
It is interesting that you put x = cty and y = class, yet was still able to get roughly the same plot as mine (or so I think, the points might be different!). I had those two variables flipped!
I also used coord_flip to flip my graph horizontally and I noticed you didn't. I am curious how you were able to make your boxplots appear horizontal then, because I can't seem to figure it out from your codes. I thought this particular graph was the hardest of all four. I compared mine and yours with our instructor's and there were additional item/commands that we both didn't include in ours.
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.
Overall, great job Ariana! I learnt a lot just by comparing my codes and yours. There were a few things that I couldn't figure out how to solve but you did, thank you for letting me learn from you! :D
|
||
```r | ||
|
||
iris$NewOrder <- factor(iris$Species, levels = c("versicolor","setosa","virginica")) |
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 also couldn't get this part! Glad I could learn by going through your code :)
```r | ||
|
||
ggplot(mpg, aes(cty, class)) + | ||
geom_jitter(aes(fill = class, color = class)) + #i dont think my points here are accurate (aka like the example figure) but i am not sure how else to get them |
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 think I had a very similar problem to you here as well, not sure what we could have done differently. It seems like calling the data set just gives us different points from what is in the example figure, suggesting that the data set was somehow changed between when the example figure was made and when we called it? Otherwise, we made the same mistake here and I haven't been able to figure it out haha.
I edited both assignments A and B in the given .Rmd files.