Skip to content

Commit

Permalink
*.default -> *.prettyB from CRAN comments
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie committed May 17, 2019
1 parent 83b7fa7 commit 0aa7cf3
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 74 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: prettyB
Type: Package
Title: Pretty Base Graphics
Version: 0.2.0
Version: 0.2.1
Authors@R: person(given="Colin", family="Gillespie",
email="[email protected]", role = c("aut", "cre"))
Maintainer: Colin Gillespie <[email protected]>
Expand Down
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ S3method(barplot,prettyB)
S3method(boxplot,prettyB)
S3method(hist,prettyB)
S3method(plot,prettyB)
export(barplotB)
export(boxplotB)
export(histB)
export(plotB)
export(barplot_p)
export(boxplot_p)
export(hist_p)
export(plot_p)
export(reset_prettyB)
export(setup_prettyB)
importFrom(grDevices,palette)
Expand Down
11 changes: 6 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## prettyB (development version)
## Version 0.2.1
* Bug fix: Don't open plotting window when loading the package
* Implement `hist()` method
* Implement `barplot()` method
* Implement `boxplot()` methods
* Now plays nicely with existing S3 plotting methods, e.g. `plot.lm()`
* Don't override default argument (CRAN request)
* Implement `hist_p()` method
* Implement `barplot_p()` method
* Implement `boxplot_p()` method
* Play nicely with existing S3 plotting methods, e.g. `plot.lm()`
* KISS: removed themes. If you want themes, use __ggplot2__
* Made grid lines solid, instead of dashed
* Add vignette
Expand Down
3 changes: 2 additions & 1 deletion R/barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ barplot.prettyB = function(height, width = 1, space = NULL, names.arg = NULL,
invisible(res)
}


#' @rdname barplot.prettyB
#' @export
barplotB = barplot.prettyB
barplot_p = barplot.prettyB
2 changes: 1 addition & 1 deletion R/boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ boxplot.prettyB = function(x, ..., range = 1.5, width = NULL, varwidth = FALSE,

#' @rdname boxplot.prettyB
#' @export
boxplotB = boxplot.prettyB
boxplot_p = boxplot.prettyB
2 changes: 1 addition & 1 deletion R/hist.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ hist.prettyB = function(x, breaks = "Sturges", freq = NULL, probability = !freq,

#' @rdname hist.prettyB
#' @export
histB = hist.prettyB
hist_p = hist.prettyB
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ plot.prettyB = function(x, y = NULL, type = "p", xlim = NULL, ylim = NULL,

#' @rdname plot.prettyB
#' @export
plotB = plot.prettyB
plot_p = plot.prettyB
12 changes: 0 additions & 12 deletions R/qqnorm_expand.R

This file was deleted.

4 changes: 2 additions & 2 deletions man/barplot.prettyB.Rd

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

4 changes: 2 additions & 2 deletions man/boxplot.prettyB.Rd

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

4 changes: 2 additions & 2 deletions man/hist.prettyB.Rd

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

4 changes: 2 additions & 2 deletions man/plot.prettyB.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test_barplot.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
test_that("Testing barplot", {
context("Barplot")
testthat::skip_on_travis()
vdiffr::expect_doppelganger("barplot basic", barplotB(VADeaths))
vdiffr::expect_doppelganger("barplot horiz", barplotB(VADeaths, horiz = TRUE))
vdiffr::expect_doppelganger("barplot basic", barplot_p(VADeaths))
vdiffr::expect_doppelganger("barplot horiz", barplot_p(VADeaths, horiz = TRUE))
vdiffr::expect_doppelganger("barplot labels",
barplotB(VADeaths, xlab = "X", ylab = "Y",
barplot_p(VADeaths, xlab = "X", ylab = "Y",
main = "Main", sub = "Sub"))

})
6 changes: 3 additions & 3 deletions tests/testthat/test_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ test_that("Testing boxplot", {
set.seed(1)
x = rlnorm(100)
testthat::skip_on_travis()
vdiffr::expect_doppelganger("Boxplot basic", boxplotB(x))
vdiffr::expect_doppelganger("Boxplot horiz", boxplotB(x, horizontal = TRUE))
vdiffr::expect_doppelganger("Boxplot basic", boxplot_p(x))
vdiffr::expect_doppelganger("Boxplot horiz", boxplot_p(x, horizontal = TRUE))
vdiffr::expect_doppelganger("Boxplot labels",
boxplotB(x, xlab = "X", ylab = "Y",
boxplot_p(x, xlab = "X", ylab = "Y",
main = "Main", sub = "Sub"))
})
6 changes: 3 additions & 3 deletions tests/testthat/test_hist.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ test_that("Testing hist", {
set.seed(1)
x = rlnorm(100)
testthat::skip_on_travis()
vdiffr::expect_doppelganger("hist basic", histB(x))
vdiffr::expect_doppelganger("hist density", histB(x, freq = FALSE))
vdiffr::expect_doppelganger("hist basic", hist_p(x))
vdiffr::expect_doppelganger("hist density", hist_p(x, freq = FALSE))
vdiffr::expect_doppelganger("hist labels",
histB(x, xlab = "X", ylab = "Y",
hist_p(x, xlab = "X", ylab = "Y",
main = "Main", sub = "Sub"))

})
20 changes: 10 additions & 10 deletions tests/testthat/test_plot.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
test_that("Testing plot", {
context("Plotting")
testthat::skip_on_travis()
vdiffr::expect_doppelganger("Plot x", plotB(1:10))
vdiffr::expect_doppelganger("Plot x-xlab", plotB(1:10, xlab = "X"))
vdiffr::expect_doppelganger("Plot x-ylab", plotB(1:10, ylab = "Y"))
vdiffr::expect_doppelganger("Plot x", plot_p(1:10))
vdiffr::expect_doppelganger("Plot x-xlab", plot_p(1:10, xlab = "X"))
vdiffr::expect_doppelganger("Plot x-ylab", plot_p(1:10, ylab = "Y"))
vdiffr::expect_doppelganger("Plot x-xlab-ylab",
plotB(1:10, xlab = "X", ylab = "Y"))
plot_p(1:10, xlab = "X", ylab = "Y"))

vdiffr::expect_doppelganger("Plot x-y-par-mfrow", {
op = par(mfrow = c(1, 2))
plotB(1:10, 11:20)
plotB(1:10, xlab = "X")
plot_p(1:10, 11:20)
plot_p(1:10, xlab = "X")
par(op)
}
)

vdiffr::expect_doppelganger("Plot x-y", plotB(1:10, 11:20))
vdiffr::expect_doppelganger("Plot x-y-xlab", plotB(1:10, 11:20, xlab = "X"))
vdiffr::expect_doppelganger("Plot x-y-ylab", plotB(1:10, 11:20, ylab = "Y"))
vdiffr::expect_doppelganger("Plot x-y", plot_p(1:10, 11:20))
vdiffr::expect_doppelganger("Plot x-y-xlab", plot_p(1:10, 11:20, xlab = "X"))
vdiffr::expect_doppelganger("Plot x-y-ylab", plot_p(1:10, 11:20, ylab = "Y"))
vdiffr::expect_doppelganger("Plot x-y-xlab-ylab",
plotB(1:10, 11:20, xlab = "X", ylab = "Y"))
plot_p(1:10, 11:20, xlab = "X", ylab = "Y"))

vdiffr::expect_doppelganger("Plot x-y-formula",
plot(iris$Sepal.Length ~ iris$Sepal.Width)
Expand Down
50 changes: 29 additions & 21 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ instead, it's meant to just make the base graphics a little bit nicer.
Due to the underlying structure of base graphics & S3 objects, some things aren't possible.
In particular, changing how non-exported plot-methods are displayed.

The general idea is by simply loading the __prettyB__ package, plots
just become a bit nicer! The current methods that are available are
The general idea is the argument signitures are
exactly the same as base graphics. But there are just a bit prettier.
The current methods that are available are

* `plot()`
* `barplot()`
* `boxplot()`
* `hist()`
* `plot_p()`
* `barplot_p()`
* `boxplot_p()`
* `hist_p()`

## Histogram examples

Expand All @@ -38,27 +39,27 @@ not always)
op = par(mfrow = c(1, 2))
reset_prettyB()
x = rlnorm(100)
graphics::hist.default(x)
hist(x)
hist_p(x)
```

Standard arguments work as well
```{r, echo = c(-1, -2)}
op = par(mfrow = c(1, 2))
reset_prettyB()
y = rnorm(100)
graphics::hist.default(y, main = "Base Graphics", sub = "Sub heading",
hist(y, main = "Base Graphics", sub = "Sub heading",
xlab = "x-axis", ylab = "y-axis")
hist(y, main = "prettyB", sub = "Sub heading", xlab = "x-axis", ylab = "y-axis")
hist_p(y, main = "prettyB", sub = "Sub heading", xlab = "x-axis", ylab = "y-axis")
```

Colours and frequencies also work as is expected
```{r, echo = c(-1, -2)}
op = par(mfrow = c(1, 2))
reset_prettyB()
z = rt(100, 4)
graphics::hist.default(z, col = "grey60", freq = FALSE)
hist(z, col = "grey60", freq = FALSE)
hist_p(z, col = "grey60", freq = FALSE)
```

## Barplot examples
Expand All @@ -68,39 +69,45 @@ The `barplot()` has an amazing number of different configurations.
```{r, out.width="100%"}
op = par(mfrow = c(1, 2))
reset_prettyB()
require(grDevices) # for colours
tN <- table(Ni <- stats::rpois(100, lambda = 3))
graphics::barplot.default(tN)
library("grDevices") # for colours
tN = table(stats::rpois(100, lambda = 3))
barplot(tN)
barplot_p(tN)
```

The following examples are taken directly from the example page of `?barplot`.
This means that sometimes the colours clash.

```{r}
reset_prettyB()
r = graphics::barplot.default(tN, col = rainbow(20))
r = barplot(tN, col = rainbow(20))
#- type = "h" plotting *is* 'bar'plot
lines(r, tN, type = "h", col = "red", lwd = 2)
r = barplot(tN, col = rainbow(20))
r = barplot_p(tN, col = rainbow(20))
#- type = "h" plotting *is* 'bar'plot
lines(r, tN, type = "h", col = "red", lwd = 2)
```

Spacing and titles still work

```{r}
reset_prettyB()
graphics::barplot.default(tN, space = 1.5, axisnames = FALSE,
sub = "barplot(..., space= 1.5, axisnames = FALSE)")
barplot(tN, space = 1.5, axisnames = FALSE,
sub = "barplot(..., space= 1.5, axisnames = FALSE)")
barplot_p(tN, space = 1.5, axisnames = FALSE,
sub = "barplot(..., space= 1.5, axisnames = FALSE)")
```

So does the `beside` argument.

```{r}
reset_prettyB()
graphics::barplot.default(VADeaths, beside = TRUE,
barplot(VADeaths, beside = TRUE,
col = c("lightblue", "mistyrose", "lightcyan",
"lavender", "cornsilk"),
legend = rownames(VADeaths), ylim = c(0, 100))
barplot(VADeaths, beside = TRUE,
barplot_p(VADeaths, beside = TRUE,
col = c("lightblue", "mistyrose", "lightcyan",
"lavender", "cornsilk"),
legend = rownames(VADeaths), ylim = c(0, 100))
Expand All @@ -110,8 +117,9 @@ barplot(VADeaths, beside = TRUE,

```{r}
par(mfrow = c(1, 2))
plot(1:100, rnorm(100), xlab = "X", ylab = "Y")
boxplot(rnorm(100))
plot_p(1:100, rnorm(100), xlab = "X", ylab = "Y")
boxplot_p(rnorm(100), horizontal = TRUE,
main = "A boxplot")
```


Expand Down

0 comments on commit 0aa7cf3

Please sign in to comment.