Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A 'ggplot2' extension that provides tools for automatically creating scales to focus on subgroups of the data plotted without removing secondary information.

License

NotificationsYou must be signed in to change notification settings

Freguglia/ggfocus

Repository files navigation

check-releaseCRAN status

Introduction

In data analysis, one may want to visualize data for a specific subgroupof observations. Simply filtering out observations that do not belong tothe subgroup may take the information out of context. Therefore, it isnecessary to have tools that allow the analyst to draw attention (focus)on that subgroup within the complete relevant information available.

Whileggplot2 is a great tool for data visualization in general,constructing graphics that focus on those subgroups may need verytroublesome manipulation of data and graphical scales (for examplecolors) together, i.e. setting low alpha for unimportant observations,coloring things in a way that highlights the focused subgroup, etc.

ggfocus allows you to build graphics that focus on those specificsubgroups by doing the scale manipulation automatically while keepingall the flexibility fromggplot. The idea behind this package is fromthis issue fromtidyverse/ggplot2.

Installing ggfocus

The package is available on CRAN, but you can also install the latestversion from Github withpak.

pak::pak("Freguglia/ggfocus")# Latest versioninstall.packages("ggfocus")# CRAN version

Usage

The workflow ofggfocus is the same as anyggplot graphic with theaddition of thefocus scales family of functions:

  • 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_alpha_focus(focus_levels, alpha_focus = 1, alpha_other = .05)
  • 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)

The user should map the variable with the grouping variable to all theaes used to highlight observations and then use these functions toautomatically create scales that highlight a specified group ofobservations.

Both the selected and unselected groups characteristics are customizablewith the parameters of focus scales. See the examples below.

Examples

Creating an example dataset.

library(ggfocus)set.seed(1)# Create an example datasetdf<-data.frame(u1= runif(300),u2= runif(300),grp= sample(LETTERS[1:10],300,replace=TRUE))head(df)#>          u1         u2 grp#> 1 0.2655087 0.67371223   C#> 2 0.3721239 0.09485786   E#> 3 0.5728534 0.49259612   B#> 4 0.9082078 0.46155184   E#> 5 0.2016819 0.37521653   E#> 6 0.8983897 0.99109922   C

Suppose that we are mainly interested in groupsA andB, but we donot want to lose theu1 andu2 information from other groups.Visualizing with focus on observations such thatgrp isA orB isshown below.

# Default scalesggplot(df, aes(x=u1,y=u2,color=grp))+  geom_point()+  ggtitle("Standard Scales")

# Focus scalesggplot(df, aes(x=u1,y=u2,color=grp,alpha=grp))+  geom_point()+  scale_color_focus(c("A","B"),color_focus= c("blue","red"))+  scale_alpha_focus(c("A","B"))+  ggtitle("Focus Scales")

Interaction with other extensions

Sinceggfocus creates the focused visualization solely by controllingscales, otherggplot extensions and types of graphics can interactwith it the same way, an example with themaps package is shown below.

library(maps)wm<- map_data("world")ggplot(wm, aes(x=long,y=lat,group=group,fill=region))+  geom_polygon(color="black")+  theme_void()+  scale_fill_focus(c("Brazil","Canada","Australia","India"),color_other="gray")

About

A 'ggplot2' extension that provides tools for automatically creating scales to focus on subgroups of the data plotted without removing secondary information.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp