Type: | Package |
Title: | Horizon Plots for 'ggplot2' |
Version: | 1.0.1 |
Maintainer: | Iker Rivas-González <ikerrivas96@gmail.com> |
Description: | A user-friendly, highly customizable R package for building horizon plots in the 'ggplot2' environment. |
License: | GPL-3 |
URL: | https://rivasiker.github.io/ggHoriPlot/, https://github.com/rivasiker/ggHoriPlot, https://CRAN.R-project.org/package=ggHoriPlot |
BugReports: | https://github.com/rivasiker/ggHoriPlot/issues |
Depends: | ggplot2, R (≥ 2.10) |
Imports: | dplyr, glue, magrittr, stringr, tidyr |
Suggests: | ggthemes, knitr, patchwork, rmarkdown, testthat (≥ 3.0.0), tidyverse, utils |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.1 |
NeedsCompilation: | no |
Packaged: | 2022-10-11 15:51:53 UTC; au595587 |
Author: | Iker Rivas-González
|
Repository: | CRAN |
Date/Publication: | 2022-10-11 16:22:33 UTC |
Distribution of COVID-19 cases in Asia
Description
A dataset containing the geographic distribution of COVID-19 cases in Asia during 2020.
Usage
COVID
Format
A data frame with 12,695 rows and 3 variables:
- date_mine
date of the measurement in yyyy-mm-dd format
- y
standardized number of cases
- countriesAndTerritories
countries and territories in Asia
Source
Compute group for stat_horizon
Description
Compute group for stat_horizon
Usage
build_horizon_df_2(data, origin, horizonscale, rm.outliers, reverse, mirror)
Arguments
data |
A data frame. |
origin |
Origin of the horizon plot. It can either be a string, namely
|
horizonscale |
Cutpoints of the horizon plot. It can either be an integer
specifying the number of ranges (default is |
rm.outliers |
If |
reverse |
IF |
mirror |
If |
Value
A data frame transformed for a horizon plot.
Average temperature in Copenhagen
Description
A dataset containing the average temperature in degrees Celsius for Copenhagen between the year 1995 and 2019.
Usage
climate_CPH
Format
A data frame with 9,132 rows and 9 variables:
- Region
geographic region
- Country
country
- State
state or territory
- City
city or town
- Month
month
- Day
day
- Year
year
- AvgTemperature
average temperature in Fahrenheit
- date_mine
data in yyyy-mm-dd format
Source
https://www.kaggle.com/sudalairajkumar/daily-temperature-of-major-cities
Average temperature in major cities of the US
Description
A dataset containing the average temperature in Fahrenheit for major cities in the US for the year 2000.
Usage
climate_US
Format
A data frame with 57,828 rows and 9 variables:
- Region
geographic region
- Country
country
- State
state or territory
- City
city or town
- Month
month
- Day
day
- Year
year
- AvgTemperature
average temperature in Fahrenheit
- date_mine
data in yyyy-mm-dd format
Source
https://www.kaggle.com/sudalairajkumar/daily-temperature-of-major-cities
https://benschmidt.org/2014/06/05/optimally-ordering-geographical-entities-in-linear-space/
Compute the origin and scale of the horizon plot
Description
Compute the origin and scale of the horizon plot
Usage
compute_ori_sca(data, origin, horizonscale)
Arguments
data |
A data frame. |
origin |
Origin of the horizon plot. It can either be a string, namely
|
horizonscale |
Cutpoints of the horizon plot. It can either be an integer
specifying the number of ranges (default is |
Value
A list with two elements: ori
, which represents the numeric
origin of the horizon plot, and vec_cut
, which is a vector with the
cutpoints for the horizon plot.
Horizon plots
Description
This function builds horizon plots in ggplot2. It allows for the customization of the origin and the horizon scale.
Usage
geom_horizon(
mapping = NULL,
data = NULL,
position = "identity",
...,
na.rm = FALSE,
show.legend = TRUE,
origin = "midpoint",
horizonscale = 6,
rm.outliers = FALSE,
reverse = FALSE,
mirror = FALSE,
inherit.aes = TRUE
)
stat_horizon(
mapping = NULL,
data = NULL,
geom = "ribbon",
position = "identity",
...,
na.rm = FALSE,
show.legend = TRUE,
inherit.aes = TRUE,
origin = "midpoint",
horizonscale = 6,
rm.outliers = FALSE,
reverse = FALSE,
mirror = FALSE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
origin |
Origin of the horizon plot. It can either be a string, namely
|
horizonscale |
Cutpoints of the horizon plot. It can either be an integer
specifying the number of ranges (default is |
rm.outliers |
If |
reverse |
IF |
mirror |
If |
inherit.aes |
If |
geom |
Used geom, default to 'ribbon' |
Details
A horizon plot is a special type of area plot in which the original data
is transformed based on an origin and a horizon scale. The data is cut in
different intervals, and the further the data is from the origin, the deeper
its color usually is. All the intervals above the origin are then stacked on
top of one another, keeping the intervals closest to the origin in the bottom
and the furthest away ones on top. Likewise, the intervals below the origin
are normally given a different color palette and they are stacked in a similar
manner in the same area as the intervals above the origin. You can learn more
about how horizon plots are built in vignette('ggHoriPlot')
or at
https://bernatgel.github.io/karyoploter_tutorial/Tutorial/PlotHorizon/PlotHorizon.html.
Value
'ggplot2' layer for building a horizon plot.
Orientation
This geom treats each axis differently and, thus, can thus have two orientations. Often the orientation is easy to deduce from a combination of the given mappings and the types of positional scales in use. Thus, ggplot2 will by default try to guess which orientation the layer should have. Under rare circumstances, the orientation is ambiguous and guessing may fail. In that case the orientation can be specified directly using the orientation
parameter, which can be either "x"
or "y"
. The value gives the axis that the geom should run along, "x"
being the default orientation you would expect for the geom.
Aesthetics
geom_horizon()
understands the following aesthetics (required aesthetics are in bold):
-
x
-
y
-
xend
-
alpha
-
colour
-
fill
Examples
# Generate data
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
# Basic plot with default colors
h <- ggplot(huron) + geom_horizon(aes(year, level))
# Add color scheme
h + theme_void() + scale_fill_hcl()
# Add cupoints
ggplot(huron) +
geom_horizon(aes(year, level, fill = ..Cutpoints..)) +
theme_void() +
scale_fill_hcl()
General color function
Description
General color function
Usage
hcl_generic(reverse, palette, ...)
Arguments
reverse |
Logical, indicating whether the palette should be inverted. |
palette |
A character string, indicating the palette to be used. |
Value
A function, that, given an integer, returns a character vector of colors of the specified palette.
Check if a variable is a whole number
Description
Check if a variable is a whole number
Usage
is.wholenumber(x, tol = .Machine$double.eps^0.5)
Arguments
x |
A number. |
tol |
Tolerance threshold. |
Value
A logical value indicating whether a number is an integer, given a certain tolerance threshold.
Internal function
Description
This function calculates the different positive and negative boundaries for each data point based on the origin and the cutpoint vector provided.
Usage
posneg(y, origin, vec)
Arguments
y |
Numeric vector of values to be transformed. |
origin |
Numeric origin of the horizon plot. |
vec |
Numeric vector of cutpoints. |
Value
A data frame, which has been transformed with the supplied origin and vector of cuts.
Distribution of repeats along the human genome
Description
A dataset containing the percentage of simple repeats in 100 kb windows along the human genome (hg38).
Usage
rmsk
Format
A data frame with 30,885 rows and 4 variables:
- genoName
chromosome name
- bin
starting coordinate of window
- bin_2
end coordinate of window
- p_repeat
percentage of repeats
Source
https://genome.ucsc.edu/cgi-bin/hgTrackUi?g=rmsk
Create your own discrete scale
Description
These functions allow you to specify your own set of mappings from levels in the data to aesthetic values.
Usage
scale_fill_hcl(..., palette = "RdYlBu", reverse = FALSE)
Arguments
... |
Arguments passed on to
|
palette |
the name of the palette to generate colors from. A list of all
available palettes can be found by running |
reverse |
If |
Details
The functions 'scale_colour_manual()', 'scale_fill_manual()', 'scale_size_manual()', etc. work on the aesthetics specified in the scale name: 'colour', 'fill', 'size', etc. However, the functions 'scale_colour_manual()' and 'scale_fill_manual()' also have an optional 'aesthetics' argument that can be used to define both 'colour' and 'fill' aesthetic mappings via a single function call (see examples). The function 'scale_discrete_manual()' is a generic scale that can work with any aesthetic or set of aesthetics provided via the 'aesthetics' argument.
Value
Scale layer for the fill aesthetic.
Peaks times for sports and leisure activities
Description
A dataset containing the peak time for doing 29 sports and leisure activities.
Usage
sports_time
Format
A data frame with 8,092 rows and 3 variables:
- activity
name of the activity
- time
time of the day, in hhmm format
- p
standardized peak
Source
https://github.com/halhen/viz-pub/blob/master/sports-time-of-day/activity.tsv