g2r comes with a number of figures that can be used to create visualisations. However, these can be used in many different ways than what is presented here in order to produce completely different looking charts; see examples, and methods.

See the graph vignette for network-related figures.

Line

The line can be controlled with shape:

  • smooth
  • dot
  • vh
  • hv
  • hvh
  • vhv
  • dash
  • line (default).
df <- data.frame(
  x = 1:99,
  y = rnorm(99, mean = rep(c(65,70,75),each=33), sd = 2) 
)

g2(df, asp(x, y)) %>% 
  fig_line()

Step

A step chart is a line chart with a shape, one of: vh, hv, hvh, or vhv.

g2(df, asp(x, y)) %>% 
  fig_line(asp(shape = "hv"))

Point

The shape of the point can also be set to:

  • circle
  • bowtie
  • cross
  • diamond
  • hexagon
  • hollow-bowtie
  • hollow-circle (default)
  • hollow-diamond
  • hollow-hexagon
  • hollow-triangle
  • hollow-triangle-down
  • line
  • hyphen
  • plus
  • tick
  • square
g2(iris, asp(Sepal.Width, Sepal.Length, color = Species)) %>% 
  fig_point()

Area

The shape of the area can also be set to:

  • area (default)
  • line
  • smooth
  • smooth-line
blockchain <- jsonlite::fromJSON(
  "https://gw.alipayobjects.com/os/antvdemo/assets/data/blockchain.json"
)

g2(blockchain, asp(date, blockchain)) %>% 
  fig_area()

Path

df <- data.frame(
  x = runif(50),
  y = runif(50) 
)

g2(df, asp(x, y)) %>% 
  fig_path()

Interval

The shape of the interval can also be set to:

  • rect (default)
  • funnel
  • hollow-rect
  • line
  • pyramid
  • tick
  • triangle
df <- data.frame(
  x = seq.Date(Sys.Date() - 29, Sys.Date(), by = "days"),
  y = rnorm(30, mean = rep(c(70,60),each=15), sd = 3)
)

g2(df, asp(x, y)) %>% 
  fig_interval()

Polygon

df <- expand.grid(x = letters, y = letters)
df$value <- rnorm(nrow(df))

g2(df, asp(x, y, color = value)) %>% 
  fig_polygon() %>% 
  gauge_color_blue()

Heatmap

g2(iris, asp(Sepal.Length, Sepal.Width, color = Petal.Length)) %>% 
  fig_heatmap() %>% 
  gauge_color(c("blue", "cyan", "lime", "yellow", "red"))

Bin

Use count (internally computed) to define the color (optional).

g2(cars, asp(speed, dist, color = count)) %>% 
  fig_bin() %>% 
  gauge_color_blue()

Use size_count to size the bins by count.

data(diamonds, package = "ggplot2")

g2(diamonds, asp(table, price, color = count)) %>% 
  fig_bin(
    type = "hex", 
    size_count = FALSE,
    stroke = "#fff"
  ) %>% 
  gauge_color_blue()