-
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
Monty Kwan HW02 #46
base: master
Are you sure you want to change the base?
Monty Kwan HW02 #46
Conversation
```{r} | ||
data(mpg) #this is a dataset from the ggplot2 package | ||
|
||
ggplot(mpg, aes(x = cty, y = hwy, color = "blue")) + |
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.
Yes, this is correct!!
<br> Either code works | ||
```{r} | ||
ggplot(mpg, aes(x=displ, y=hwy)) + | ||
geom_point(color="blue") |
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.
Very nice!!
geom_point(mapping = aes(x = displ, y = hwy, color = class), size = 3) + | ||
theme(legend.direction = "horizontal") + | ||
theme(legend.position = c(.6, .8)) + | ||
theme(legend.title = element_blank()) |
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.
Great!!
mpg %>% | ||
ggplot(mapping = aes(x = displ, y = hwy)) + | ||
geom_point(mapping=aes(color = drv)) + | ||
geom_smooth(se = F, color="yellow") #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 Monty,
I ran your code, and it is giving the same result as mine! what I have for the last line: geom_smooth(se = F, aes(color = NULL))
so it just commended to ignore the color differences from groups, and draw the line.
Your way def works well too!
```{r} | ||
ggplot(data = mpg, mapping = aes(x = manufacturer, y = cty, fill=manufacturer)) + | ||
geom_boxplot() + | ||
theme(axis.text.x = element_text(angle = 45, vjust=0.5)) |
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.
Awesome!!
labs(x = "Diamond Cut", y= "Number of Diamonds", title="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)) + | ||
#geom_text(aes(x="Premium", y=4500), label="My Best Diamonds,\n of course") also works but slow hehe | ||
annotate("text", x = "Premium", y = 4500, label ="My Best Diamonds,\n of course") |
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.
Like your annotate and subtitle, I didn't include those, learnt a lot!
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.
Also did a quick Googling for the difference between "geom bar" and "geom histogram", seems that they are the same actually
#changing order of factor to un-alphabetical (non-default) | ||
ggplot(iris, aes(x= Sepal.Length, y= Petal.Length )) + | ||
geom_point(aes(color = Species, shape = Species)) + | ||
geom_smooth(formula = y~x , method = 'lm', se= F, color= 'black') + facet_wrap(~Species, scales="free_y") |
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.
If you do "levels = c("versicolor","setosa","virginica")", the dots and triangles should be fine? maybe!
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.
Leant from your scales="free_y"!
geom_text_repel(corvette, mapping = aes(x= displ, y=hwy, label = paste("Corvette,", year))) + | ||
geom_point(data=corvette, color = 'blue') + | ||
labs(title = "Corvettes are a bit of an outlier") | ||
#mapping calls displ and hwy from corvette specifically, not mpg's displ and hwy |
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 Monty, I think calling corvette already did the job, so no need for mapping calls display and hwy?
Mine was without them, and seemed worked ok?
geom_text_repel(data = corvette, label = paste("Corvette,",corvette$year)
No description provided.