Title: | Horizon Plots for 'ggplot2' |
---|---|
Description: | A user-friendly, highly customizable R package for building horizon plots in the 'ggplot2' environment. |
Authors: | Iker Rivas-González [aut, cre] |
Maintainer: | Iker Rivas-González <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-11-09 04:54:59 UTC |
Source: | https://github.com/rivasiker/gghoriplot |
A dataset containing the average temperature in degrees Celsius for Copenhagen between the year 1995 and 2019.
climate_CPH
climate_CPH
A data frame with 9,132 rows and 9 variables:
geographic region
country
state or territory
city or town
month
day
year
average temperature in Fahrenheit
data in yyyy-mm-dd format
https://www.kaggle.com/sudalairajkumar/daily-temperature-of-major-cities
A dataset containing the average temperature in Fahrenheit for major cities in the US for the year 2000.
climate_US
climate_US
A data frame with 57,828 rows and 9 variables:
geographic region
country
state or territory
city or town
month
day
year
average temperature in Fahrenheit
data in yyyy-mm-dd format
https://www.kaggle.com/sudalairajkumar/daily-temperature-of-major-cities
https://benschmidt.org/2014/06/05/optimally-ordering-geographical-entities-in-linear-space/
A dataset containing the geographic distribution of COVID-19 cases in Asia during 2020.
COVID
COVID
A data frame with 12,695 rows and 3 variables:
date of the measurement in yyyy-mm-dd format
standardized number of cases
countries and territories in Asia
This function builds horizon plots in ggplot2. It allows for the customization of the origin and the horizon scale.
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 )
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 )
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' |
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.
'ggplot2' layer for building a horizon plot.
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.
geom_horizon()
understands the following aesthetics (required aesthetics are in bold):
x
y
xend
alpha
colour
fill
# 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()
# 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()
A dataset containing the percentage of simple repeats in 100 kb windows along the human genome (hg38).
rmsk
rmsk
A data frame with 30,885 rows and 4 variables:
chromosome name
starting coordinate of window
end coordinate of window
percentage of repeats
https://genome.ucsc.edu/cgi-bin/hgTrackUi?g=rmsk
These functions allow you to specify your own set of mappings from levels in the data to aesthetic values.
scale_fill_hcl(..., palette = "RdYlBu", reverse = FALSE)
scale_fill_hcl(..., palette = "RdYlBu", reverse = FALSE)
... |
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 |
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.
Scale layer for the fill aesthetic.
A dataset containing the peak time for doing 29 sports and leisure activities.
sports_time
sports_time
A data frame with 8,092 rows and 3 variables:
name of the activity
time of the day, in hhmm format
standardized peak
https://github.com/halhen/viz-pub/blob/master/sports-time-of-day/activity.tsv
https://eagereyes.org/blog/2017/joy-plots