Last active
September 25, 2017 14:19
-
-
Save aravindhebbali/9c1e4475fe554377bb3b20acf0b71231 to your computer and use it in GitHub Desktop.
ggplot2: Legends - Part 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install | |
install.packages('ggplot2') | |
install.packages('readr') | |
# load | |
library(ggplot2) | |
library(readr) | |
# Plot | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) | |
# Title | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(name = "Horsepower") | |
# Range | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(range = c(3, 6)) | |
# Limits | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(limits = c(0, 400)) | |
# Breaks | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(breaks = c(100, 200, 300, 400)) | |
# Labels | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(breaks = c(100, 200, 300, 400), | |
labels = c("Hundred", "2 Hundred", "3 Hundred", "4 Hundred")) | |
# Putting it all together | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, size = hp)) + | |
scale_size_continuous(name = "Horsepower", range = c(3, 6), | |
limits = c(0, 400), breaks = c(100, 200, 300, 400), | |
labels = c("Hundred", "2 Hundred", "3 Hundred", "4 Hundred")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment