Description Usage Arguments Value Cosmetic Tips Also See Examples
View source: R/ggplot_horizon.R
A horizon plot breaks the Y dimension down using colours. This is useful when visualising y values spanning a vast range and / or trying to highlight outliers without losing context of the rest of the data. Horizon plots are best viewed in an apsect ratio of very low vertical length.
1 2 | ggplot_horizon(dtData, cXColumnName, cYColumnName, bandwidth = NULL,
vcGroupingColumnNames = NULL)
|
dtData |
Data set which may include other columns apart from date and values. |
cXColumnName |
Column name of dates. |
cYColumnName |
Column name of values. |
bandwidth |
the width of one band of Y values. easier to differentiate between the bands. |
vcGroupingColumnNames |
The set of columns which together define the group for the chart to operate within If you plan to facet your plot, you should specify the same column names to this argument. |
Returns a gpplot friendly object which means the user can use ggplot scales, etc. to modify the look.
The minimalist look can be achieved by appending the
following chunk of code to the example output object:
+
xlab(NULL) +
ylab(NULL) +
scale_fill_continuous(low = 'green', high = 'red') +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position = 'none',
strip.background = element_blank(),
# strip.text = element_blank(), # useful if only one year of data
plot.background = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
panel.border = element_blank()
) +
coord_fixed( 0.5 * diff(range(dfData$x)) / diff(range(dfData$y)))
stat_horizon
, a less polished but more
flexible alternative.
1 2 3 4 5 6 7 8 9 10 11 | {
library(ggplot2)
set.seed(1)
dfData = data.frame(x = 1:1000, y = cumsum(rnorm(1000)))
p1 = ggplot_horizon(dfData, 'x', 'y')
p1
# add new geoms or colours
p1 +
geom_text(label = '!!!') +
scale_colour_continuous(low = 'red', high = 'green')
}
|
Loading required package: ggplot2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.