Package 'ggbump'

Title: Bump Chart and Sigmoid Curves
Description: A geom for ggplot to create bump plots. Can be good to use for showing rank over time.
Authors: David Sjoberg
Maintainer: David Sjoberg <[email protected]>
License: MIT + file LICENSE
Version: 0.1.99999
Built: 2025-02-13 04:28:18 UTC
Source: https://github.com/davidsjoberg/ggbump

Help Index


geom_bump

Description

Creates a ggplot that makes a smooth rank over time. To change the 'smooth' argument you need to put it outside of the 'aes' of the geom. Uses the x and y aestethics. Usually you want to compare multiple lines and if so, use the 'color' aestethic. To change the direction of the curve to 'vertical' set 'direction = "y'

Usage

geom_bump(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  smooth = 8,
  direction = "x",
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

geom

change geom

position

change position

na.rm

remove missing values

show.legend

show legend in plot

smooth

how much smooth should the curve have? More means steeper curve.

direction

the character x or y depending of smoothing direction

inherit.aes

should the geom inherits aestethics

...

other arguments to be passed to the geom

Value

ggplot layer

Examples

library(ggplot2)
library(ggbump)
df <- data.frame(country = c(
  "India", "India", "India",
  "Sweden", "Sweden", "Sweden",
  "Germany", "Germany", "Germany",
  "Finland", "Finland", "Finland"),
year = c(2011, 2012, 2013,
2011, 2012, 2013,
2011, 2012, 2013,
2011, 2012, 2013),
month = c("January", "July", "November",
          "January", "July", "November",
          "January", "July", "November",
          "January", "July", "November"),
rank = c(4, 2, 2, 3, 1, 4, 2, 3, 1, 1, 4, 3))

# Contingous x axis
ggplot(df, aes(year, rank, color = country)) +
  geom_point(size = 10) +
  geom_bump(size = 2)

# Discrete x axis
ggplot(df, aes(month, rank, color = country)) +
  geom_bump(size = 2)

geom_sigmoid

Description

Creates a ggplot that makes a smooth rank over time. To change the 'smooth' argument you need to put it outside of the 'aes' of the geom. Uses the x, xend, y and yend aestethics. Make sure each sigmoid curve is its own group.

Usage

geom_sigmoid(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  smooth = 8,
  direction = "x",
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x, xend, y and yend need to be numeric.

data

provide you own data

geom

xhange geom

position

change position

na.rm

remove missing values

show.legend

show legend in plot

smooth

how much smooth should the curve have? More means steeper curve.

direction

the character x or y depending of smoothing direction

inherit.aes

should the geom inherits aestethics

...

other arguments to be passed to the geom

Value

ggplot layer

Examples

library(ggplot2)
df <- data.frame(x = 1:6,
       y = 5:10,
       xend = 7,
       yend = -3:2)

ggplot(df, aes(x = x, xend = xend, y = y, yend = yend, color = factor(x))) +
  geom_sigmoid()

ggbump extensions to ggplot2

Description

These ggproto objects are participate in the ggproto class extension mechanism provided by ggplot2. They are typically of no concern, as they can be used through the 'geom_*()' functions.


rank_sigmoid

Description

Creates a longer dataframe with coordinates for a smoothed line.

Usage

rank_sigmoid(x, y, smooth = 8, direction = "x")

Arguments

x

vector

y

vector

smooth

smooth parameter. Higher means less smoothing

direction

the character x or y depending of smoothing direction

Value

a data frame


sigmoid

Description

Creates a longer dataframe with coordinates for a smoothed line.

Usage

sigmoid(x_from, x_to, y_from, y_to, smooth = 5, n = 100, direction = "x")

Arguments

x_from

start x value

x_to

end x value

y_from

start y value

y_to

end y values

smooth

smooth parameter. Higher means less smoothing

n

number of point that should be smoothed

direction

the character x or y depending on direction of smoothing

Value

a data frame