Title: | Themes and Helpers for ggplot2 |
---|---|
Description: | This package provides helper functions for ggplot graphs and maps. |
Authors: | Pascal Burkhard [aut, cre] |
Maintainer: | Pascal Burkhard <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-26 08:28:43 UTC |
Source: | https://github.com/Nenuial/ggeo |
Copitalize plot title
ggeo_capitalize_title(plot)
ggeo_capitalize_title(plot)
plot |
A ggplot2 object |
A ggplot2 object
ggplot(aes(x = speed, y = dist), data = cars) + geom_point() + labs(title = "Fast cars !") + ggeo_remove_title()
ggplot(aes(x = speed, y = dist), data = cars) + geom_point() + labs(title = "Fast cars !") + ggeo_remove_title()
A function that uses geotools::gtl_crs_proj()
to
get the CRS configuration and applies it to a ggplot2
map.
ggeo_coord(code, ...)
ggeo_coord(code, ...)
code |
A string with the CRS identifier |
... |
Arguments passed on to
|
A ggplot2 coord object
rnaturalearth::ne_countries() |> ggplot2::ggplot() + ggplot2::geom_sf() + ggeo_coord("eqearth")
rnaturalearth::ne_countries() |> ggplot2::ggplot() + ggplot2::geom_sf() + ggeo_coord("eqearth")
These functions extend the scales package and allow formatting labels.
ggeo_label_sci_10(x) ggeo_label_pyramid(x) ggeo_label_abs_percent(x)
ggeo_label_sci_10(x) ggeo_label_pyramid(x) ggeo_label_abs_percent(x)
x |
Number to format |
ggeo_label_sci_10()
is used to format numbers with a clean
scientific format using a multiplier and not the ugly notation
using the letter e.
ggeo_label_pyramid()
is used for population pyramids with
absolute numbers. It formats the absolute number using
ggeo_label_sci_10()
.
ggeo_label_abs_percent()
is also used for population pyramids
but with relative numbers (percents). It uses scales::percent()
and absolute numbers.
A formatted string for the scales
This function can be used to modify the breaks of a ggplot2 scale. It is specifically designed to remove the some breaks in the scale.
ggeo_remove_breaks(original_func, remove_list = list())
ggeo_remove_breaks(original_func, remove_list = list())
original_func |
The function to create the breaks. Use the break functions from the scales |
remove_list |
The values to remove from the scale. |
A list
ggplot2::ggplot(ggplot2::aes(x = speed, y = dist), data = cars) + ggplot2::geom_point() + ggplot2::labs(title = "Fast cars!") + ggplot2::scale_y_continuous( breaks = ggeo::ggeo_remove_breaks(scales::breaks_pretty(6), list(0)), )
ggplot2::ggplot(ggplot2::aes(x = speed, y = dist), data = cars) + ggplot2::geom_point() + ggplot2::labs(title = "Fast cars!") + ggplot2::scale_y_continuous( breaks = ggeo::ggeo_remove_breaks(scales::breaks_pretty(6), list(0)), )
Remove plot title
ggeo_remove_title(plot)
ggeo_remove_title(plot)
plot |
A ggplot2 object |
A ggplot2 object
ggplot(aes(x = speed, y = dist), data = cars) + geom_point() + labs(title = "Fast cars !") + ggeo_remove_title()
ggplot(aes(x = speed, y = dist), data = cars) + geom_point() + labs(title = "Fast cars !") + ggeo_remove_title()
Save function
ggeo_save( plot, filename, width = geotools::gtl_options("plot_standard_width"), height = geotools::gtl_options("plot_standard_height"), dpi = 72, units = "cm", ... )
ggeo_save( plot, filename, width = geotools::gtl_options("plot_standard_width"), height = geotools::gtl_options("plot_standard_height"), dpi = 72, units = "cm", ... )
plot |
The ggplot2 object to save (should be piped in ;) |
filename |
Path for filename (with extension!) |
width |
The plot width.
Defaults to keynote width ( |
height |
The plot height.
Defaults to keynote height ( |
dpi |
The DPI. Default is 72. |
units |
Units. Default is cm. |
... |
Arguments passed on to
|
cars |> ggplot2::ggplot(ggplot2::aes(x = speed, y = dist)) + ggplot2::geom_point() -> simple_plot ggeo_save(simple_plot, "simple_plot.png")
cars |> ggplot2::ggplot(ggplot2::aes(x = speed, y = dist)) + ggplot2::geom_point() -> simple_plot ggeo_save(simple_plot, "simple_plot.png")
Return a color palette with option to center diverging palettes
ggeopal_center(n, center, params)
ggeopal_center(n, center, params)
n |
Number of colors |
center |
Where is the center (counted from the left). Use -1 for non diverging palettes. |
params |
Parameters to pass on to paletteer |
A vector of colors
Return a paletteer palette depending on
ggeopal_chooser(n, params)
ggeopal_chooser(n, params)
n |
Number of colors |
params |
Parameters to pass on to paletteer Must be a list with:
|
A vector of colors
Generate colors from a HEX color using HCL palette
ggeopal_hex_to_hcl(hex, n = 4)
ggeopal_hex_to_hcl(hex, n = 4)
hex |
A string HEX color |
n |
Number of colors wanted |
A string vector of HEX colors
ggeopal_hex_to_hcl("#222b4c") |> prismatic::color() ggeopal_hex_to_hcl("#222b4c", 6) |> prismatic::color()
ggeopal_hex_to_hcl("#222b4c") |> prismatic::color() ggeopal_hex_to_hcl("#222b4c", 6) |> prismatic::color()
Create gradient for palette colors
ggeopal_to_gradient(pal)
ggeopal_to_gradient(pal)
pal |
A vector of colors |
Print color vectors
ggeopal_to_gradient("#dd4123") ggeopal_to_gradient("#ee950b") ggeopal_to_gradient("#0b6b8b")
ggeopal_to_gradient("#dd4123") ggeopal_to_gradient("#ee950b") ggeopal_to_gradient("#0b6b8b")
A function that returns the ggplot theme elements for the chosen theme.
ggeotheme( theme = c("ghibli_mononoke", "islamic_samarquand", "pomological_green", "pomological_red", "nord_blue", "swiss_red", "purple", "doc", "oc_exams"), main = "main", plot = "plot", ..., mode = c("light", "dark"), base = ggplot2::theme_bw() )
ggeotheme( theme = c("ghibli_mononoke", "islamic_samarquand", "pomological_green", "pomological_red", "nord_blue", "swiss_red", "purple", "doc", "oc_exams"), main = "main", plot = "plot", ..., mode = c("light", "dark"), base = ggplot2::theme_bw() )
theme |
Name of the theme to use. One of "ghibli_mononoke", "islamic_samarquand", "pomological_green", "pomological_red", "nord_blue", "swiss_red", "purple", "doc" or "oc_exams" |
main |
One of |
plot |
One of |
... |
Arguments passed on to
|
mode |
One of |
base |
A ggplot2 theme |
An object of class ggplot2::theme()
.
cars |> ggplot2::ggplot(ggplot2::aes(x = speed, y = dist)) + ggplot2::geom_point() + ggeotheme("ghibli_mononoke")
cars |> ggplot2::ggplot(ggplot2::aes(x = speed, y = dist)) + ggplot2::geom_point() + ggeotheme("ghibli_mononoke")
These functions can be used to modify the theme of a highcharts plot.
hc_purple_theme(hc) hc_samarqand_theme(hc) hc_pomogreen_theme(hc) hc_jerusalem_theme(hc) hc_web_theme(hc) hc_dark_web_theme(hc)
hc_purple_theme(hc) hc_samarqand_theme(hc) hc_pomogreen_theme(hc) hc_jerusalem_theme(hc) hc_web_theme(hc) hc_dark_web_theme(hc)
hc |
A highcharts object |
A highcharts object
highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_purple_theme() highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_samarqand_theme() highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_web_theme()
highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_purple_theme() highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_samarqand_theme() highcharter::hchart( cars, "point", highcharter::hcaes(x = speed, y = dist) ) |> hc_web_theme()