tinyplot icon indicating copy to clipboard operation
tinyplot copied to clipboard

tinyplot not working with layout?

Open devSJR opened this issue 9 months ago • 4 comments

I was trying to use tinyplot with layout. However, there appears to be an issue.

works: all plots basically are drawn, but not in the matrix layout

layout(matrix(c(1, 1, 1, 1, 2, 2, 3, 3), nrow = 2, ncol = 4, byrow = TRUE ))

tinyplot(Petal.Width ~ Sepal.Width | Species, data = iris)
tinyplot(Sepal.Width ~ Petal.Length | Species, data = iris)
tinyplot(Petal.Width ~ Petal.Length | Species, data = iris)

doesn't work: all plots basically are drawn in the matrix layout, when the by argument is not used (both with by and formula syntax)

layout(matrix(c(1, 1, 1, 1, 2, 2, 3, 3),
  nrow = 2, ncol = 4, byrow = TRUE
))

tinyplot(Petal.Width ~ Sepal.Width, data = iris)
tinyplot(Sepal.Width ~ Petal.Length, data = iris)
tinyplot(Petal.Width ~ Petal.Length, data = iris)

devSJR avatar Feb 27 '25 21:02 devSJR

Yeah, unfortunately we probably have to mark this as won't fix. The tl;dr version is that tinyplot needs to hijack the window arrangement to position things the legend, facet, etc. Internally, we use par(mfrow) & co. for this, which as you probably know, makes it incompatible with layout.

OTOH, turning the legend off does work:

library(tinyplot)

layout(matrix(c(1, 1, 1, 1, 2, 2, 3, 3), nrow = 2, ncol = 4, byrow = TRUE ))

tinyplot(Petal.Width ~ Sepal.Width | Species, data = iris, legend = FALSE)
tinyplot(Sepal.Width ~ Petal.Length | Species, data = iris, legend = FALSE)
tinyplot(Petal.Width ~ Petal.Length | Species, data = iris, legend = FALSE)

Created on 2025-02-27 with reprex v2.1.1

grantmcdermott avatar Feb 28 '25 02:02 grantmcdermott

Alright. Would it be possible to give a(n) warning/error message in case layout is used? Something like trace(layout)?

devSJR avatar Feb 28 '25 07:02 devSJR

Thanks @devSJR that's a good suggestion. At a minimum, we could probably do a better job of documenting this incompatibility.

I want to take a another stab at improving layout compatibility with the legend behavior, though. It feels to me like maybe we could get this to work, even if facets are a no-go. But I'll only be able to take a look at it in a few weeks.

grantmcdermott avatar Mar 01 '25 16:03 grantmcdermott

Sure, all good. I think communicating this more prominent will do the trick for the time being. Technical solutions would be optimal of course, but from my side at least there's no need to hurry. Keep up the good work.

devSJR avatar Mar 01 '25 18:03 devSJR