Title: | Scales that Focus Specific Levels in your ggplot() |
---|---|
Description: | A 'ggplot2' extension that provides tools for automatically creating scales to focus on subgroups of the data plotted without losing other information. |
Authors: | Victor Freguglia [aut, cre] |
Maintainer: | Victor Freguglia <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0.9999 |
Built: | 2025-01-19 04:31:11 UTC |
Source: | https://github.com/freguglia/ggfocus |
'ggfocus()' is deprecated. Add focus scales with 'scale_color_focus()', 'scale_fill_focus()', 'scale_alpha_focus()', ... instead.
Creates a 'ggplot' object with focus scales from another 'ggplot' object.
ggfocus( p, var, focus_levels, focus_aes = c("color", "alpha", "fill"), color_focus = NULL, color_other = "black", alpha_focus = 1, alpha_other = 0.05 )
ggfocus( p, var, focus_levels, focus_aes = c("color", "alpha", "fill"), color_focus = NULL, color_other = "black", alpha_focus = 1, alpha_other = 0.05 )
p |
a 'ggplot' object. |
var |
Sets. |
focus_levels |
levels to be highlited. |
focus_aes |
list of aesthetics used to highlight. "color","alpha" and "fill" are available. |
color_focus |
vector of colors (or a single color) for focused levels. |
color_other |
color for non-focused levels. |
alpha_focus , alpha_other
|
alpha value for focused and non-focused levels. |
a ggplot object with focusing scales.
Victor Freguglia
library(ggplot2) p <- ggplot(iris,aes(x=Sepal.Length,y=Petal.Length)) + geom_point() ggfocus(p, Species, "versicolor")
library(ggplot2) p <- ggplot(iris,aes(x=Sepal.Length,y=Petal.Length)) + geom_point() ggfocus(p, Species, "versicolor")
Scale that focus on specific levels.
scale_alpha_focus(focus_levels, alpha_focus = 1, alpha_other = 0.2) scale_color_focus( focus_levels, color_focus = NULL, color_other = "gray", palette_focus = "Set1" ) scale_fill_focus( focus_levels, color_focus = NULL, color_other = "gray", palette_focus = "Set1" ) scale_linetype_focus(focus_levels, linetype_focus = 1, linetype_other = 3) scale_shape_focus(focus_levels, shape_focus = 8, shape_other = 1) scale_size_focus(focus_levels, size_focus = 3, size_other = 1)
scale_alpha_focus(focus_levels, alpha_focus = 1, alpha_other = 0.2) scale_color_focus( focus_levels, color_focus = NULL, color_other = "gray", palette_focus = "Set1" ) scale_fill_focus( focus_levels, color_focus = NULL, color_other = "gray", palette_focus = "Set1" ) scale_linetype_focus(focus_levels, linetype_focus = 1, linetype_other = 3) scale_shape_focus(focus_levels, shape_focus = 8, shape_other = 1) scale_size_focus(focus_levels, size_focus = 3, size_other = 1)
focus_levels |
character vector with levels to focus on. |
alpha_focus |
'alpha' value for focused levels. Defaults to 1. |
alpha_other |
'alpha' value for other levels. Defaults to 0.05. |
color_focus |
color(s) for focused levels (a single value or a vector with the same length as the number of highlighted levels). |
color_other |
color for other levels. |
palette_focus |
If 'color_focus' is not specified, provide a pelette from RColorBrewer to pick colors. |
linetype_focus |
vector of 'linetype' value(s) for focused levels with length 1 or equal to 'focus_levels'. Defaults to 1. |
linetype_other |
'linetype' value for other levels. Defaults to 3. |
shape_focus |
'shape' value for focused levels. Defaults to 8. |
shape_other |
'shape' value for other levels. Defaults to 1. |
size_focus |
'size' value for focused levels. Defaults to 3. |
size_other |
'size' value for other levels. Defaults to 1. |
Use RColorBrewer::display.brewer.all()
to see the palettes
available.
ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, alpha = Species)) + geom_point() + scale_alpha_focus(focus_levels = "versicolor") ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, color = Species)) + geom_point() + scale_color_focus(focus_levels = "setosa", color_focus = "red") ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, color = Species)) + geom_point() + scale_color_focus(focus_levels = c("setosa", "virginica"), color_focus = c("red", "blue")) ggplot(mtcars, aes(x = wt, y = mpg, color = rownames(mtcars))) + geom_point() + scale_color_focus(focus_levels = c("Mazda RX4", "Merc 230"), palette_focus = "Set2") ggplot(iris,aes(x = Petal.Length, group = Species, fill = Species)) + geom_histogram() + scale_fill_focus(focus_levels = "versicolor", color_focus = "red") ggplot(iris,aes(x = Petal.Length, y = Sepal.Length, shape = Species)) + geom_point() + scale_shape_focus(focus_levels = "versicolor") ggplot(iris,aes(x = Petal.Length, y = Sepal.Length, size = Species)) + geom_point() + scale_size_focus(focus_levels = "versicolor")
ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, alpha = Species)) + geom_point() + scale_alpha_focus(focus_levels = "versicolor") ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, color = Species)) + geom_point() + scale_color_focus(focus_levels = "setosa", color_focus = "red") ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, color = Species)) + geom_point() + scale_color_focus(focus_levels = c("setosa", "virginica"), color_focus = c("red", "blue")) ggplot(mtcars, aes(x = wt, y = mpg, color = rownames(mtcars))) + geom_point() + scale_color_focus(focus_levels = c("Mazda RX4", "Merc 230"), palette_focus = "Set2") ggplot(iris,aes(x = Petal.Length, group = Species, fill = Species)) + geom_histogram() + scale_fill_focus(focus_levels = "versicolor", color_focus = "red") ggplot(iris,aes(x = Petal.Length, y = Sepal.Length, shape = Species)) + geom_point() + scale_shape_focus(focus_levels = "versicolor") ggplot(iris,aes(x = Petal.Length, y = Sepal.Length, size = Species)) + geom_point() + scale_size_focus(focus_levels = "versicolor")