-
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
Hw02 submission (this time with all files from repo - whoops) #29
base: master
Are you sure you want to change the base?
Conversation
ggplot() + | ||
geom_point(mapping = aes(x = displ, y = hwy, color = class), alpha = 1, size = 2) + | ||
# alpha refers to the opacity of a geom | ||
theme(legend.position = "top") |
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.
You can also use legend.position = c(x, y) to overlay the legend with the plot, where with x and y you specify the position on x and y axes. It's kinda tricky, because x/y has to be between 0 and 1, so you sort of have to calculate the fraction of your axis range, i.e. if your y range is 0-8 and you want it to be at y = 4, then you would specify y = 0.5, since halfway to the top. Maybe there's a more straightforward way, but I haven't found it yet. Also legend.position = "none" will remove the legend!
geom_bar(aes(fill = clarity), position = position_dodge()) + | ||
theme(legend.position = "right") + | ||
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", |
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.
Cool! I didn't know you can rename x and y axes just with x and y parameters within labs(). Also a hint - you can introduce a line break by adding \n in the character string. I can see that it doesn't happen automatically. And I did move the annotation by using annotate() and specifying x and y positions ("Premium" and 4500 in this case). Hope this helps!
data("iris") | ||
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + | ||
geom_point(data = subset(iris, Species %in% c("setosa", "virginica", "versicolor"))) + | ||
facet_wrap(~Species) + |
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.
Congrats on finding a way to group the data into panels. Honestly I spent most of my time on this graph. In order to re-order the panels I found a way to generate a new subset with re-ordered data (iris$Species2 <- factor(iris$Species, levels = c("versicolor", "setosa", "virginica")). and then passed this subset to facet_wrap(). And to change scales range I used scales = free_y. Anyway, GJ! That was a tricky one.
No description provided.