scale_x_continuous()
scale_y_date()
scale_x_log10()
scale_color_hue()
scale_fill_brewer()
scale_shape_manual()
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point() + scale_x_log10() + scale_color_brewer(palette = "Set2")
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point() + scale_x_log10() + scale_color_brewer(palette = "Set2")
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point() + scale_x_log10() + scale_color_brewer(palette = "Set2")
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point() + scale_x_log10() + scale_color_brewer(palette = "Set2")
scale_color_distiller()
and scale_color_viridis_c()
. Check the help pages for different palette options.gender
. Try scale_color_brewer()
.scale_color_manual()
. Use values = c("#E69F00", "#56B4E9")
in the function call.name
argument in whatever scale function you're using.diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point()
diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c()
diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + scale_color_brewer()
diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + scale_color_manual(values = c("#E69F00", "#56B4E9"))
diabetes %>% ggplot(aes(waist, hip, col = gender)) + geom_point() + scale_color_manual(name = "Sex", values = c("#E69F00", "#56B4E9"))
theme_gray()
(default), theme_minimal()
, theme_light()
, etc.theme_gray()
(default), theme_minimal()
, theme_light()
, etc.theme()
mtcars %>%ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
mtcars %>% ggplot(aes(hp, mpg, col = factor(cyl))) + geom_point(size = 3) + scale_x_log10() + scale_colour_brewer(name = "Cylinders", palette = "Set2") + theme_minimal() + theme( axis.text = element_text(size = 16), legend.text = element_text(size = 8, face = "bold"), legend.direction = "horizontal" )
element | draws |
---|---|
element_blank() | nothing (remove element) |
element_line() | lines |
element_rect() | borders and backgrounds |
element_text() | text |
theme()
to change the legend to the bottom with legend.position = "bottom"
.axis.ticks
argument to element_blank()
element_text()
. Check the help page if you don't know what option to change.diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c()
diabetes %>% ggplot(aes(waist, hip, col = weight)) + geom_point() + scale_color_viridis_c() + theme_minimal() + theme( legend.position = "bottom", axis.ticks = element_blank(), axis.title = element_text(size = 16) )
?rnorm
, ?Distributions
big_data <- tibble(x = rnorm(10000), y = rnorm(10000))
big_data %>% ggplot(aes(x, y)) + geom_point()
Transparency
Binning
big_data %>% ggplot(aes(x, y)) + geom_point(alpha = .05)
big_data %>% ggplot(aes(x, y)) + geom_bin2d()
big_data %>% ggplot(aes(x, y)) + geom_hex()
diamonds
data set from ggplot2. How many rows does it have?diamonds
carat
vs. price
. How's it look?geom_point()
with 2d bins.diamonds %>% ggplot(aes(x = carat, price)) + geom_point()
diamonds %>% ggplot(aes(x = carat, price)) + geom_point(alpha = .05)
diamonds %>% ggplot(aes(x = carat, price)) + geom_bin2d()
diamonds %>% ggplot(aes(x = carat, price)) + geom_hex()
ggtitle()
labs(title = "My Awesome Plot")
xlab()
, ylab()
labs(x = "X Label", y = "Y Label")
scale_*()
functionslabs(color = "Wow, labs does everything", fill = "Yup")
scale_*()
functionslabs(color = "Wow, labs does everything", fill = "Yup")
theme(legend.position = "none")
hip
and pounds for weight
). You can use either labs()
or xlab()
and ylab()
scale_linetype()
and set the name
argument to "Sex".ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12)
ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) + labs(x = "Weight (lbs)", y = "Hip (inches)") + ggtitle("Hip and Weight by Sex") + scale_linetype(name = "Sex")
ggplot(diabetes, aes(weight, hip, linetype = gender)) + geom_jitter(alpha = .2, size = 2.5) + geom_smooth(color = "black", se = FALSE) + theme_bw(base_size = 12) + labs( title = "Hip and Weight by Sex", x = "Weight (lbs)", y = "Hip (inches)", linetype = "Sex" )
ggsave(filename = "figure_name.png", plot = last_plot(), dpi = 320)
ggsave("diabetes_weight_hip.png", dpi = 320)
ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + <GEOM_FUNCTION>() + <SCALE_FUNCTION>() + <THEME_FUNCTION>()
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |