Title: | Easy Access to 'ggplot2' Commands |
---|---|
Description: | Provides a series of aliases to commonly used but difficult to remember 'ggplot2' sequences. |
Authors: | Jonathan Carroll [aut, cre] , Alicia Schep [aut] , Jonathan Sidi [aut] , Bob Rudis [ctb] , Mohamed El Fodil Ihaddaden [ctb], Thomas Neitmann [ctb] |
Maintainer: | Jonathan Carroll <[email protected]> |
License: | GPL (>=2) |
Version: | 0.1.5 |
Built: | 2024-11-03 06:19:48 UTC |
Source: | https://github.com/jonocarroll/ggeasy |
Update the title(s) of the specified aesthetic, or all aesthetics at once.
easy_add_legend_title(..., teach = FALSE)
easy_add_legend_title(..., teach = FALSE)
... |
A list of new name-value pairs. The name should be an aesthetic. If only a character value is provided then all legend titles will be changed to that. |
teach |
print longer equivalent |
a theme
object
Jonathan Carroll
library(ggplot2) # Add legend title to a specific aesthetic ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_add_legend_title(col = "Number of Cylinders") # Add legend title to all aesthetics ggplot(mtcars, aes(wt, mpg, colour = cyl)) + geom_point() + easy_add_legend_title("Number of Cylinders")
library(ggplot2) # Add legend title to a specific aesthetic ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_add_legend_title(col = "Number of Cylinders") # Add legend title to all aesthetics ggplot(mtcars, aes(wt, mpg, colour = cyl)) + geom_point() + easy_add_legend_title("Number of Cylinders")
Change legend position, direction, or justification.
easy_change_legend( what = c("position", "direction", "justification"), to, teach = FALSE ) easy_move_legend( to = c("right", "none", "left", "bottom", "top"), teach = FALSE ) easy_legend_at(to = c("right", "none", "left", "bottom", "top"), teach = FALSE) easy_rotate_legend(to = c("vertical", "horizontal"), teach = FALSE) easy_adjust_legend(to = c("left", "right", "center"), teach = FALSE)
easy_change_legend( what = c("position", "direction", "justification"), to, teach = FALSE ) easy_move_legend( to = c("right", "none", "left", "bottom", "top"), teach = FALSE ) easy_legend_at(to = c("right", "none", "left", "bottom", "top"), teach = FALSE) easy_rotate_legend(to = c("vertical", "horizontal"), teach = FALSE) easy_adjust_legend(to = c("left", "right", "center"), teach = FALSE)
what |
legend component to modify
( |
to |
to what to set the legend component should be changed |
teach |
print longer equivalent |
Due to limitations of ggplot2
this will apply to all legends at once
a theme
object
Jonathan Carroll
library(ggplot2) # Move legends to bottom ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_move_legend("bottom") # Make legends horizontal ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_rotate_legend("horizontal") # Justify legends to the bottom and justify to the right ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_move_legend("bottom") + easy_adjust_legend("right")
library(ggplot2) # Move legends to bottom ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_move_legend("bottom") # Make legends horizontal ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_rotate_legend("horizontal") # Justify legends to the bottom and justify to the right ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_move_legend("bottom") + easy_adjust_legend("right")
Change any of the text parameters such as
easy_change_text( which = .all_theme_els, what = .all_element_text, to = NULL, teach = FALSE ) .all_theme_els .all_element_text easy_all_text_size(size = NULL, teach = FALSE) easy_all_text_color(color = NULL, teach = FALSE) easy_all_text_colour(colour = NULL, teach = FALSE) easy_text_size(which = .all_theme_els, size = NULL, teach = FALSE) easy_text_color(which = .all_theme_els, color = NULL, teach = FALSE) easy_text_colour(which = .all_theme_els, colour = NULL, teach = FALSE) easy_x_axis_title_size(size, teach = FALSE) easy_y_axis_title_size(size, teach = FALSE) easy_x_axis_labels_size(size = NULL, teach = FALSE) easy_y_axis_labels_size(size = NULL, teach = FALSE) easy_plot_title_size(size = NULL, teach = FALSE) easy_title_size(size = NULL, teach = FALSE) easy_plot_subtitle_size(size = NULL, teach = FALSE) easy_subtitle_size(size = NULL, teach = FALSE) easy_plot_caption_size(size = NULL, teach = FALSE) easy_caption_size(size = NULL, teach = FALSE) easy_plot_legend_size(size = NULL, teach = FALSE) easy_legend_title_size(size = NULL, teach = FALSE) easy_plot_legend_title_size(size = NULL, teach = FALSE) easy_legend_size(size = NULL, teach = FALSE) easy_center_title(teach = FALSE) easy_title_bold() easy_title_regular() easy_title_plain()
easy_change_text( which = .all_theme_els, what = .all_element_text, to = NULL, teach = FALSE ) .all_theme_els .all_element_text easy_all_text_size(size = NULL, teach = FALSE) easy_all_text_color(color = NULL, teach = FALSE) easy_all_text_colour(colour = NULL, teach = FALSE) easy_text_size(which = .all_theme_els, size = NULL, teach = FALSE) easy_text_color(which = .all_theme_els, color = NULL, teach = FALSE) easy_text_colour(which = .all_theme_els, colour = NULL, teach = FALSE) easy_x_axis_title_size(size, teach = FALSE) easy_y_axis_title_size(size, teach = FALSE) easy_x_axis_labels_size(size = NULL, teach = FALSE) easy_y_axis_labels_size(size = NULL, teach = FALSE) easy_plot_title_size(size = NULL, teach = FALSE) easy_title_size(size = NULL, teach = FALSE) easy_plot_subtitle_size(size = NULL, teach = FALSE) easy_subtitle_size(size = NULL, teach = FALSE) easy_plot_caption_size(size = NULL, teach = FALSE) easy_caption_size(size = NULL, teach = FALSE) easy_plot_legend_size(size = NULL, teach = FALSE) easy_legend_title_size(size = NULL, teach = FALSE) easy_plot_legend_title_size(size = NULL, teach = FALSE) easy_legend_size(size = NULL, teach = FALSE) easy_center_title(teach = FALSE) easy_title_bold() easy_title_regular() easy_title_plain()
which |
which element to change (see |
what |
what attribute of the element to change (see |
to |
value to which the attribute should be set |
teach |
print longer equivalent |
size |
size to set attributes to |
color |
colo(u)r to set attributes to |
colour |
colo(u)r to set attributes to |
An object of class character
of length 15.
An object of class character
of length 10.
a theme
object which can be used in
ggplot2
calls
Jonathan Carroll
library(ggplot2) # make all text larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_all_text_size(22) # also works if accidentally using easy_text_size(n) # make the x and y axis text larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_text_size(c("axis.text.x", "axis.text.y"), 22) # make the x axis labels larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_x_axis_labels_size(22) # make the plot title larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + labs(title = "My Plot") + easy_plot_title_size(22) # make the legend title larger ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_plot_legend_title_size(22) # make all the text red ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_all_text_color("red") # make all the text 45 degrees, right-justified ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_change_text(what = "angle", to = 45) + easy_change_text(what = "hjust", to = 1) # make just x-axis text 45 degrees, right-justified ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_change_text(which = "axis.text.x", what = "angle", to = 45) + easy_change_text(which = "axis.text.x", what = "hjust", to = 1)
library(ggplot2) # make all text larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_all_text_size(22) # also works if accidentally using easy_text_size(n) # make the x and y axis text larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_text_size(c("axis.text.x", "axis.text.y"), 22) # make the x axis labels larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_x_axis_labels_size(22) # make the plot title larger ggplot(mtcars, aes(mpg, hp)) + geom_point() + labs(title = "My Plot") + easy_plot_title_size(22) # make the legend title larger ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_plot_legend_title_size(22) # make all the text red ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_all_text_color("red") # make all the text 45 degrees, right-justified ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_change_text(what = "angle", to = 45) + easy_change_text(what = "hjust", to = 1) # make just x-axis text 45 degrees, right-justified ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(fill = gear)) + easy_change_text(which = "axis.text.x", what = "angle", to = 45) + easy_change_text(which = "axis.text.x", what = "hjust", to = 1)
Applies same logic as labs
but uses as default
the column label attribute if present as the variable label in the plot.
easy_labs(..., teach = FALSE)
easy_labs(..., teach = FALSE)
... |
A list of new name-value pairs. The name should either be an aesthetic, or one of "title", "subtitle", or "caption" |
teach |
print longer equivalent |
iris_labs <- iris lbl <- c('Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Flower Species') labelled::var_label(iris_labs) <- split(lbl,names(iris_labs)) p <- ggplot2::ggplot(iris_labs,ggplot2::aes(x=Sepal.Length,y=Sepal.Width))+ ggplot2::geom_line(ggplot2::aes(colour=Species)) p p + easy_labs() p + easy_labs(title = "Plot Title", subtitle = 'Plot Subtitle', x = 'x axis label') p + easy_labs(teach = TRUE)
iris_labs <- iris lbl <- c('Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Flower Species') labelled::var_label(iris_labs) <- split(lbl,names(iris_labs)) p <- ggplot2::ggplot(iris_labs,ggplot2::aes(x=Sepal.Length,y=Sepal.Width))+ ggplot2::geom_line(ggplot2::aes(colour=Species)) p p + easy_labs() p + easy_labs(title = "Plot Title", subtitle = 'Plot Subtitle', x = 'x axis label') p + easy_labs(teach = TRUE)
easy_remove_axes by default removes both axes, but can remove only x or y if "x" or "y" is given to the 'which' argument
easy_remove_axes( which = c("both", "x", "y"), what = c("ticks", "title", "text", "line"), teach = FALSE ) easy_remove_y_axis(what = c("ticks", "title", "text", "line"), teach = FALSE) easy_remove_x_axis(what = c("ticks", "title", "text", "line"), teach = FALSE)
easy_remove_axes( which = c("both", "x", "y"), what = c("ticks", "title", "text", "line"), teach = FALSE ) easy_remove_y_axis(what = c("ticks", "title", "text", "line"), teach = FALSE) easy_remove_x_axis(what = c("ticks", "title", "text", "line"), teach = FALSE)
which |
which axis or axes to remove, by default "both" |
what |
axis components to remove
( |
teach |
print longer equivalent |
easy_remove_x_axis and easy_remove_y_axis remove just the x or y axis, respectively.
a theme
object which can be used in
ggplot2
calls
Alicia Schep
library(ggplot2) # Remove all axes ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_axes() # remove just x axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_x_axis() # can also use: ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_axes("x") # Remove y axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_y_axis() # Remove just the ticks # Remove y axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_y_axis(what = "ticks")
library(ggplot2) # Remove all axes ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_axes() # remove just x axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_x_axis() # can also use: ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_axes("x") # Remove y axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_y_axis() # Remove just the ticks # Remove y axis ggplot(mtcars, aes(wt, mpg)) + geom_point() + easy_remove_y_axis(what = "ticks")
Easily remove any gridlines from a ggplot
.
easy_remove_gridlines( axis = c("both", "x", "y"), minor = TRUE, major = TRUE, teach = FALSE ) easy_remove_x_gridlines(minor = TRUE, major = TRUE, teach = FALSE) easy_remove_y_gridlines(minor = TRUE, major = TRUE, teach = FALSE)
easy_remove_gridlines( axis = c("both", "x", "y"), minor = TRUE, major = TRUE, teach = FALSE ) easy_remove_x_gridlines(minor = TRUE, major = TRUE, teach = FALSE) easy_remove_y_gridlines(minor = TRUE, major = TRUE, teach = FALSE)
axis |
From which axis should grid lines be removed? By default |
minor |
Should minor grid lines be removed? By default |
major |
Should major grid lines be removed? By default |
teach |
Should the equivalent |
a theme
object which can be used in
ggplot2
calls
Thomas Neitmann
library(ggplot2) p <- ggplot(mtcars, aes(hp, mpg)) + geom_point() # remove all grid lines at once p + easy_remove_gridlines() # remove all minor grid lines p + easy_remove_gridlines(major = FALSE) # remove all major grid lines p + easy_remove_gridlines(minor = FALSE) # remove x gridlines p + easy_remove_x_gridlines() # or p + easy_remove_gridlines(axis = "x") # remove y gridlines p + easy_remove_y_gridlines()
library(ggplot2) p <- ggplot(mtcars, aes(hp, mpg)) + geom_point() # remove all grid lines at once p + easy_remove_gridlines() # remove all minor grid lines p + easy_remove_gridlines(major = FALSE) # remove all major grid lines p + easy_remove_gridlines(minor = FALSE) # remove x gridlines p + easy_remove_x_gridlines() # or p + easy_remove_gridlines(axis = "x") # remove y gridlines p + easy_remove_y_gridlines()
With no argument, will remove all legends. Provide the name(s) of specific aesthetic to remove only certain legends.
easy_remove_legend(..., teach = FALSE)
easy_remove_legend(..., teach = FALSE)
... |
optional name(s) specific aesthetics for which to remove the legend |
teach |
print longer equivalent |
either a theme
object or a
guides
object, both of which can be used in
ggplot2
calls
Alicia Schep
library(ggplot2) # Remove all legends ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend() # remove just size legend ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend("size") # can also use: ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend(size) # Remove more than one ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend(size, color)
library(ggplot2) # Remove all legends ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend() # remove just size legend ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend("size") # can also use: ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend(size) # Remove more than one ggplot(mtcars, aes(wt, mpg, colour = cyl, size = hp)) + geom_point() + easy_remove_legend(size, color)
Easily remove legend title Remove the legend title
easy_remove_legend_title(teach = FALSE)
easy_remove_legend_title(teach = FALSE)
teach |
print longer equivalent |
a theme
object
library(ggplot2) # remove legend title from all aesthetics ggplot(mtcars, aes(wt, mpg, colour = cyl)) + geom_point() + easy_remove_legend_title()
library(ggplot2) # remove legend title from all aesthetics ggplot(mtcars, aes(wt, mpg, colour = cyl)) + geom_point() + easy_remove_legend_title()
x
axis labelsA shortcut to
easy_rotate_labels( which = c("both", "x", "y"), angle = 90, side = c("left", "middle", "right"), teach = FALSE ) easy_rotate_x_labels( angle = 90, side = c("left", "middle", "right"), teach = FALSE ) easy_rotate_y_labels( angle = 90, side = c("left", "middle", "right"), teach = FALSE )
easy_rotate_labels( which = c("both", "x", "y"), angle = 90, side = c("left", "middle", "right"), teach = FALSE ) easy_rotate_x_labels( angle = 90, side = c("left", "middle", "right"), teach = FALSE ) easy_rotate_y_labels( angle = 90, side = c("left", "middle", "right"), teach = FALSE )
which |
which axis or axes to rotate, by default "both" |
angle |
angle through which the text should be rotated. Can also be one of "startattop" or "startatbottom" to define where the text should start. |
side |
horizontal justification of the text before rotation |
teach |
print longer equivalent |
theme(axis.text.x = element_text(angle, hjust))
a theme
object which can be used in
ggplot2
calls.
library(ggplot2) ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_rotate_labels()
library(ggplot2) ggplot(mtcars, aes(mpg, hp)) + geom_point() + easy_rotate_labels()