grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
226 stars 7 forks source link

Wishlist: General #116

Closed harrelfe closed 1 month ago

harrelfe commented 8 months ago

There is an example in the following section of R Workflow where in one plot I use many of the most commonly used ggplot2 features. I suggest checking that the new package has counterparts to those. https://hbiostat.org/rflow/graphics#sec-graphics-ggplot2

The use of plotmath expressions in labels (Mathjax/LaTeX would be even better) is important, as is the ability to add spike histograms to bottom or side of plots, or along fitted curves. Spike histograms are demonstrated elsewhere in R Workflow.

harrelfe commented 7 months ago

Since this comment may be buried in a closed issue I’ll reiterate it here. tinyplot connotes a small graphics image. Please come up with a better name for the package and function, that connotes leanness or base graphics.

vincentarelbundock commented 7 months ago

Maybe you missed it, but the project author responded to this specific suggestion here: https://github.com/grantmcdermott/tinyplot/issues/22#issuecomment-1959511826

Also, for what it's worth, several packages on CRAN (including my own tinytable) use the prefix "tiny" to connote "lightweight" or "dependency-free". None of these CRAN packages produce anything "small" per se:

tiny

zeileis commented 7 months ago

Thanks, Vincent, I was about to write the same!

Also, Grant really weighed all the different options very carefully! This wasn't easy because different people had already voiced different irreconcilable opinions with varying degrees of emphasis. Hence it's best to respect this decision and move on.

eddelbuettel commented 7 months ago

@harrelfe I had this written yesterday but decided not to post it (then) as it seemed to not be worth it to put gas on the fire. But as you seem to unable to let go, I am posting it now (unchanged).

As best as I can tell, and with all due respect, you are reading this issue, and the room, wrongly.


With all due respect @harrelfe I would beg to differ: https://www.tinyverse.org/

The prefix has by now a fairly well known and understood meaning at CRAN based on a collection of greatest hits such as tinytest, the recent yet excellent tinytable and more.

It is this argument we brought forth and into which @grantmcdermott bought in, as did participants in two surveys.

harrelfe commented 7 months ago

Thanks for the responses. I understand that tiny has been used by other packages. I just want to register that tinyplot has the wrong connotation no matter how many similar uses have occurred. An app like tinytex or tinyr have sensible names because what is after tiny is a system and you can have a tiny system. The word plot in my humble opinion is a different matter.

grantmcdermott commented 1 month ago

Hi @harrelfe, thanks for the suggestion. I think we can close this issue, since tinyplot can reproduce the plots in question. The plotmath examples (incl. your hlab function) appear to play nicely with this package.

Quick examples.

library(tinyplot)
library(Hmisc)
#> Loading required package: Hmisc
#> 
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:base':
#> 
#>     format.pval, units

# https://hbiostat.org/rflow/graphics#sec-graphics-ggplot2
set.seed(1)
x <- 1:50
label(x) <- 'Acceleration'
units(x) <- 'm/s^2'
y <- x + (x / 3) ^2 + rnorm(50, 0, 20)
label(y) <- 'Y'
units(y) <- 'm^2/kg^3'
z <- sample(LETTERS[1:3], 50, TRUE)

tinyplot(
  y ~ x | z, pch = 19,
  xlab = hlab(x), ylab = hlab(y)
)


# Slightly fancier version
op = tpar(las = 1, bg = "grey60")
plt(
  y ~ x | z, pch = 19,
  xlab = hlab(x), ylab = hlab(y),
  palette = "viridis",
  axes = "t", grid = grid()
)

tpar(op)

Created on 2024-08-26 with reprex v2.1.1

Spiked histogram example from this chapter of your book.

library(tinyplot)
library(data.table)
library(Hmisc)
#> 
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:base':
#> 
#>     format.pval, units

getHdata("stressEcho")
d <- stressEcho
setDT(d)

# Using type = "histogram" with many breaks
plt(
  ~maxhr, d,
  facet = ~ecg, facet.args = list(bg = "grey90"),
  type = "histogram", breaks = 200,
  xlab = hlab(maxhr),
  frame = FALSE, grid = TRUE
)

# Using `Hmisc::spikecomp` for manual calculation of breaks, followed by type = "h" 
s  <- d[, spikecomp(maxhr, tresult='segments'), by=ecg]
plt(
  y2~x, s,
  facet = ~ecg, facet.args = list(bg = "grey90"),
  col = "dodgerblue",
  type = "h", 
  xlab = hlab(maxhr),
  frame = FALSE, grid = TRUE
)

Created on 2024-08-26 with reprex v2.1.1