Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmt committed Sep 10, 2018
1 parent 2acb80f commit c3fb675
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: console.plot
Title: Plots for the R console
Version: 0.0.3
Version: 0.0.4
Authors@R:
person(given = "Benjamin",
family = "Tremblay",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(console.plot)
importFrom(stats,approx)
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# console.plot 0.0.4 #

## User-facing ##

- plots with `plot.height = 5` now display correctly
- xaxis tick labels now better align with ticks

## Internal ##

- got rid of hex codes
- added stats import
- fixed approx errors from duplicate x values

# console.plot 0.0.3 #

## User-facing ##
Expand Down
22 changes: 11 additions & 11 deletions R/console_plot_axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ console.plot.axis <- function(plot.lines, plot.width, plot.height, ylim, xlim,

plot.lines[1] <- paste0(" ", s$hori, s$vert.left, " ", plot.lines[1])

plot.lines[length(plot.lines)] <- paste0(" ", s$hori, s$vert.left, " ",
plot.lines[length(plot.lines)] <- paste0(" ", s$hori, s$vert.left, " ",
plot.lines[length(plot.lines)])

mid.y <- round(plot.height / 2)
mid.y <- round(plot.height / 2 + 0.01)

plot.lines[mid.y] <- paste0(" ", s$hori, s$vert, " ", plot.lines[mid.y])
plot.lines[mid.y] <- paste0(" ", s$hori, s$vert.left, " ", plot.lines[mid.y])

mid.y1 <- round(plot.height * 0.25)
if (mid.y1 == 1) mid.y1 <- 2
mid.y3 <- round(plot.height * 0.75)

plot.lines[mid.y1] <- paste0(" ", s$vert.left, " ", plot.lines[mid.y1])
Expand All @@ -24,7 +25,7 @@ console.plot.axis <- function(plot.lines, plot.width, plot.height, ylim, xlim,
plot.lines[-yaxis.skip] <- paste0(paste0(" ", s$vert, " "),
plot.lines[-yaxis.skip])

mid.x <- round(plot.width / 2)
mid.x <- round(plot.width / 2 + 0.01)
mid.x1 <- round(plot.width * 0.25)
mid.x3 <- round(plot.width * 0.75)

Expand Down Expand Up @@ -53,21 +54,20 @@ console.plot.axis <- function(plot.lines, plot.width, plot.height, ylim, xlim,

# add axis scales

xaxis.scale <- c(gsub(" ", "", formatC(xlim[1], digits = 4, width = 5)),
gsub(" ", "", formatC(mean(xlim), digits = 4, width = 5)),
gsub(" ", "", formatC(xlim[2], digits = 4, width = 5)))
xaxis.scale <- c(format(as.character(xlim[1]), digits = 4, width = 5, justify = "centre"),
format(as.character(mean(xlim)), digits = 4, width = 5, justify = "centre"),
format(as.character(xlim[2]), digits = 4, width = 5, justify = "centre"))
yaxis.scale <- c(gsub(" ", "", formatC(ylim[1], digits = 4, width = 5)),
gsub(" ", "", formatC(mean(ylim), digits = 4, width = 5)),
gsub(" ", "", formatC(ylim[2], digits = 4, width = 5)))

y.offset <- 8
y.offset.scale <- y.offset - nchar(yaxis.scale)

xaxis.scale.filler <- c(" ",
paste(rep(" ", mid.x - sum(nchar(xaxis.scale[1:2])) +
round(nchar(xaxis.scale[2]) / 2)),
xaxis.scale.filler <- c(" ",
paste(rep(" ", mid.x - 5),
collapse = ""),
paste(rep(" ", mid.x - nchar(xaxis.scale[3])),
paste(rep(" ", mid.x - 6),
collapse = ""))
xaxis.scale <- paste0(xaxis.scale.filler[1], xaxis.scale[1],
xaxis.scale.filler[2], xaxis.scale[2],
Expand Down
1 change: 1 addition & 0 deletions R/console_plot_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ console.plot.types <- function(x, y, groups, plot.width, plot.height, point,
y.i.1 <- y.i[j]
y.i.2 <- y.i[j + 1]

if (x.i.1 == x.i.2) x.i.2 <- x.i.2 + 0.1 # approx won't work otherwise
x.y.new <- approx(c(x.i.1, x.i.2), c(y.i.1, y.i.2),
n = plot.width * plot.height)
x.y.new <- unique(data.frame(x.y.new[[1]], x.y.new[[2]]))
Expand Down
57 changes: 57 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
get_symbols <- function(ascii = FALSE) {

if (!ascii) {

all.symbols <- c(8226, 215, 43, 8718, 9670, 9650, 9744, 9671, 9651, 9737,
9733, 9734, 10035, 9746, 8865, 8857, 8853, 10023)
all.symbols <- sapply(all.symbols, intToUtf8)
all.symbols <- c(all.symbols, "o", "@", "#", "$", "%", "&", ">", "<", "?",
letters[-15])

all.lines <- c(9475, 9479, 9483, 9551, 9553, 9474, 9478, 9482, 9550)
all.lines <- sapply(all.lines, intToUtf8)
all.lines <- c(all.lines, "|", "-", "/", "\\", ".", ",", "~")

vert <- intToUtf8(9474)
vert.left <- intToUtf8(9508)
vert.right <- intToUtf8(9500)
hori <- intToUtf8(9472)
hori.down <- intToUtf8(9516)
hori.up <- intToUtf8(9524)
corner.bot.left <- intToUtf8(9492)
corner.bot.right <- intToUtf8(9496)
corner.top.left <- intToUtf8(9484)
corner.top.right <- intToUtf8(9488)
tick.x.minor <- intToUtf8(9589)
cross <- intToUtf8(9532)

} else {

all.symbols <- c("o", "@", "#", "$", "%", "&", ">", "<", "?",
letters[-15])

all.lines <- c("|", "-", "/", "\\", ".", ",", "~")

vert <- "|"
vert.left <- "|"
vert.right <- "|"
hori <- "-"
hori.down <- "-"
hori.up <- "-"
corner.bot.left <- "-"
corner.bot.right <- "-"
corner.top.left <- "-"
corner.top.right <- "-"
tick.x.minor <- "|"
cross <- "+"

}

list(all.symbols = all.symbols, all.lines = all.lines, vert.right = vert.right,
vert = vert, vert.left = vert.left, hori = hori, hori.down = hori.down,
hori.up = hori.up, corner.bot.left = corner.bot.left,
corner.bot.right = corner.bot.right, corner.top.left = corner.top.left,
corner.top.right = corner.top.right, tick.x.minor = tick.x.minor,
cross = cross)

}
13 changes: 12 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
options(ascii = FALSE)
#' console.plot: View R plots in the console
#'
#' @details
#' Create text-based plots.
#'
#' @docType package
#' @name console.plot-pkg
#'
#' @importFrom stats approx
NULL

options(ascii = FALSE)
13 changes: 13 additions & 0 deletions man/console.plot-pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions man/console.plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3fb675

Please sign in to comment.