Last active
September 25, 2017 10:47
-
-
Save aravindhebbali/ef2b665173cf7cfe17093f3dcb052035 to your computer and use it in GitHub Desktop.
ggplot2: Legends Part - 2
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') | |
# library | |
library(ggplot2) | |
library(readr) | |
# Plot | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) | |
# Title | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(name = "Cylinders", | |
values = c("red", "blue", "green")) | |
# Values | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(values = c("red", "blue", "green")) | |
# Labels | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(values = c("red", "blue", "green"), | |
labels = c('Four', 'Six', 'Eight')) | |
# Limits | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(values = c("red", "blue", "green"), | |
limits = c(4, 6, 8)) | |
# Breaks | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(values = c("red", "blue", "green"), | |
breaks = c(4, 6, 8)) | |
# Putting it all together... | |
ggplot(mtcars) + | |
geom_point(aes(disp, mpg, fill = factor(cyl)), shape = 22) + | |
scale_fill_manual(name = "Cylinders", values = c("red", "blue", "green"), | |
labels = c('Four', 'Six', 'Eight'), limits = c(4, 6, 8), breaks = c(4, 6, 8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment