ggvariety: Plot a variety

View source: R/ggvariety.R

ggvarietyR Documentation

Plot a variety

Description

Uses geom_contour() and ggplot() to plot an mpoly object representing a variety in 2D space.

Usage

ggvariety(mp, xlim = c(-1, 1), ylim = c(-1, 1), n = 101, nx = n, ny = n, ...)

Arguments

mp

an mpoly object

xlim

vector representing x bounds

ylim

vector representing y bounds

n

number of mesh points in each dimension

nx

number of mesh points in the abcissa (x)

ny

number of mesh points in the ordinate (y)

...

additional parameters to pass to geom_contour()

Value

A ggplot object containing variety plot

Author(s)

Phillip Hossu, Ryan Hebdon, Chong Sun, Grant Innerst, David Kahle

Examples


## basic usage
##################################################

ggvariety("y - x")
ggvariety("y - x^2")
ggvariety("x^2 + y^2 - 1")
ggvariety(c("x^2 + y^2 - 1", "y - x"))

# x = cos(m t + p)
# y = sin(n t + q)
(p <- lissajous(3, 2,  -pi/2, 0))
(p <- lissajous(4, 3,  -pi/2, 0))
(p <- lissajous(5, 4,  -pi/2, 0))
(p <- lissajous(3, 3,  0, 0))
(p <- lissajous(5, 5,  0, 0))
(p <- lissajous(7, 7,  0, 0))
ggvariety(p, n = 201)


## setting limits
##################################################

ggvariety("y - x^2")
ggvariety("y - x^2", xlim = c(-2,2), ylim = c(-2,2))



## ggplot2 styling
##################################################

library("ggplot2")
ggvariety("x^2 + y^2 - 1") + coord_equal()
ggvariety("x^2 + y^2 - 1", color = "red") + coord_equal()
ggvariety("x^2 + y^2 - 1", size = 2) + coord_equal()
ggvariety("x^2 + y^2 - 1", size = 2, alpha = .2) + coord_equal()
ggvariety("x^2 + y^2 - 1", linetype = 2) + coord_equal()
ggvariety("x^2 + y^2 - 1") + coord_equal() + theme_bw()
ggvariety("x^2 + y^2 - 1") + coord_equal() + theme_classic()
ggvariety("x^2 + y^2 - 1") + coord_equal() + theme_void()

ggvariety(c("x^2 + y^2 - 1", "(x^2 + y^2)^3 - 4 x^2 y^2")) +
  coord_equal() + theme_void() +
  scale_color_manual(values = c("red", "blue"), guide = "none")



## possible issues
##################################################

# at a low level, ggvariety() uses grDevices::contourLines()
# to numerically detect zero crossings. this is an imperfect process,
# so you may see gaps where none exist. as a general strategy, upping
# the number of sampled points on the grid is recommended.
# the below are commented to cut check time; they run

# ggvariety("y^2 - x^3 - x^2") + coord_equal()
# ggvariety("y^2 - x^3 - x^2", n = 201) + coord_equal()
# ggvariety(mp(c("x^2 + y^2 - 1", "y - x")))


dkahle/algstat documentation built on May 23, 2023, 12:29 a.m.