The goal of ggvwline is to to provide a set of geom functions that can be drawn with variable widths.
ggvwline
is not on CRAN yet (but will probably at some point), you can
install it from github:
## install.packages("devtools")
devtools::install_github("houyunhuang/ggvwline)
library(ggplot2)
library(ggvwline)
library(grid)
df1 <- data.frame(
x = c(0.2, 0.8),
y = c(2/3, 2/3))
df2 <- data.frame(
x = c(0.2, 0.5, 0.8),
y = c(0.2, 0.5, 0.2))
width <- widthSpline(unit(c(12, 12, 25, 0), "mm"), d = c(0, 0.7, 0.7, 1),
shape = 0.01, rep = TRUE)
ggplot(df1, aes(x, y)) +
geom_brush_xspline(width0 = width) +
geom_brush_xspline(data = df2, width0 = width) +
coord_cartesian(xlim = c(0,1), ylim = c(0, 1))
df3 <- data.frame(x = c(0.2, 0.5, 0.8),
y = c(0.3, 0.7, 0.3))
arrowBrush <- list(x=c(-1, 1, -1, 0), y=c(-1, 0, 1, 0))
ggplot(df3, aes(x, y)) +
geom_brush_xspline(brush = arrowBrush, spacing = 1:2) +
geom_brush_xspline(width = 0.02, colour = 'grey40', fill = "grey40") +
coord_cartesian(xlim = c(0.1, 0.9), ylim = c(0.2, 0.8))
t <- seq(0, 2 * pi, length.out = 45)[-45]
df4 <- data.frame(x = cos(t),
y = sin(t),
group = rep(LETTERS[1:4], each = 11))
width1 <- widthSpline(unit(c(0, 5, 12, 0), "mm"), d = c(0, 0.8, 0.8, 1),
shape = 0.01, rep = TRUE)
width2 <- widthSpline(unit(c(5, 5, 12, 0), "mm"), d = c(0, 0.8, 0.8, 1),
shape = 0.01, rep = TRUE)
ggplot(df4, aes(x, y, group = group, fill = group)) +
geom_brush_xspline(width0 = width1) +
coord_fixed(xlim = c(-1.1, 1.1), ylim = c(-1.1, 1.1))
ggplot(df4, aes(x, y, group = group, fill = group)) +
geom_brush_xspline(width0 = width2) +
coord_fixed(xlim = c(-1.1, 1.1), ylim = c(-1.1, 1.1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.