Skip to content

Commit

Permalink
lines
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Feb 5, 2024
1 parent 3463068 commit 5f1b672
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: tinytable
Type: Package
Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats
Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Version: 0.0.3.9002
Version: 0.0.3.9003
Depends:
R (>= 4.1.0)
Enhances:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
New:

- `j` argument in `style_tt()` and `format_tt()` now accepts a string vector to match columns. Issue #122
- Line plots: `plot_tt(fun = "line")`


## 0.0.3
Expand Down
15 changes: 14 additions & 1 deletion R/plot_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ plot_tt <- function(x,
}

if (is.character(fun)) {
assert_choice(fun, c("histogram", "density", "bar"))
assert_choice(fun, c("histogram", "density", "bar", "line"))
} else {
assert_function(fun, null.ok = TRUE)
}
Expand All @@ -81,6 +81,9 @@ plot_tt <- function(x,
} else if (identical(fun, "density")) {
fun <- rep(list(tiny_density), length(data))

} else if (identical(fun, "line")) {
fun <- rep(list(tiny_line), length(data))

} else if (identical(fun, "bar")) {
for (idx in seq_along(data)) {
assert_numeric(data[[idx]], len = 1, name = "data[[1]]")
Expand Down Expand Up @@ -227,3 +230,13 @@ tiny_bar <- function(d, color = "black", xlim = 0:1, ...) {
graphics::barplot(d, horiz = TRUE, col = color, xlim = xlim)
}
}


tiny_line <- function(d, xlim = 0:1, color = "black", ...) {
function() {
if (!inherits(d, "data.frame") || !"x" %in% names(d) || !"y" %in% names(d)) {
stop("The data to plot a `line` must be a data frame with columns `x` and `y`.", call. = FALSE)
}
plot(d$x, d$y, type = "l", col = color, axes = FALSE, ann = FALSE, lwd = 50)
}
}
9 changes: 7 additions & 2 deletions vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -747,14 +747,19 @@ dat <- data.frame(
Variables = c("mpg", "hp", "qsec"),
Histogram = "",
Density = "",
Bar = ""
Bar = "",
Line = ""
)
# random data for sparklines
lines <- lapply(1:3, \(x) data.frame(x = 1:10, y = rnorm(10)))
tt(dat) |>
plot_tt(j = 2, fun = "histogram", data = plot_data) |>
plot_tt(j = 3, fun = "density", data = plot_data, color = "darkgreen") |>
plot_tt(j = 4, fun = "bar", data = list(2, 3, 6), color = "orange") |>
style_tt(j = 2:4, align = "c")
plot_tt(j = 5, fun = "line", data = lines, color = "blue") |>
style_tt(j = 2:5, align = "c")
```

### Custom plots: Base `R`
Expand Down

0 comments on commit 5f1b672

Please sign in to comment.