tinyplot icon indicating copy to clipboard operation
tinyplot copied to clipboard

Improve `tinytheme("ipsum")`?

Open grantmcdermott opened this issue 7 months ago • 5 comments

I was playing around with some code yesterday and realised that our "ipsum" theme implementation is actually quite far off the original. Compare:

library(ggplot2)
library(hrbrthemes)

ggplot(mtcars, aes(mpg, wt, col = factor(cyl))) +
  geom_point() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)", 
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes"#,
       # caption="Brought to you by the letter 'g'"
       ) + 
  theme_ipsum() +
  scale_colour_ipsum()

library(tinyplot)
tinytheme("ipsum")

plt(
  wt ~ mpg | factor(cyl), mtcars,
  xlab="Fuel efficiency (mpg)", ylab="Weight (tons)", 
  main="Seminal ggplot2 scatterplot example",
  sub="A plot that is only useful for demonstration purposes"
)

While our theme implementations are more in the spirit of "inspired by" than intended to be exact replicas, bringing them closer into alignment only requires a few tweaks:

tinytheme("ipsum", family = "Arial Narrow", font.main = 2, font.sub = 1,
          palette.qualitative = ipsum_pal()(9))

plt(
  wt ~ mpg | factor(cyl), mtcars,
  xlab="Fuel efficiency (mpg)", ylab="Weight (tons)", 
  main="Seminal ggplot2 scatterplot example",
  sub="A plot that is only useful for demonstration purposes"
)

Of the above changes, the following would be very straightforward to implement:

  • Change main and sub font families. (Optional, but also easy: Reduce size of axis titles and tick labels)
  • Use the same colors for palette.qualitative as ipsum_pal()(9)

Changing the default family to "Arial Narrow" is more complicated, since I'm not fully up to speed on precisely how wide the expected coverage is. (Maybe @hrbrmstr or @eddelbuettel could weigh in based on their experience?) But we could perhaps implement some internal logic that checks for an installed version of Arial Narrow first, before defaulting back to "sans".

P.S. Even if we changed tinytheme("ipsum") to closer match the original, I would still want to keep the current version. Maybe as tinytheme("ipsum2")?

grantmcdermott avatar May 20 '25 17:05 grantmcdermott

Spacing between main and sub also affects readability, I think.

I'm not a big fan of bold, but I'd be very happy if we kept different versions of it.

vincentarelbundock avatar May 20 '25 17:05 vincentarelbundock

Spacing between main and sub also affects readability, I think.

True. I'm not sure that we have a good way to introduce extra spacing here under the current logic, but I'm at the dentist rn so have time to think about it ;-)

grantmcdermott avatar May 20 '25 17:05 grantmcdermott

I think it would be a good strategy to have "ipsum" closer to the original and "ipsum2" as a simpler version that is more "inspired by" but with some tweaks.

I also agree with Vincent that spacing would be important. Also, can we easily set a strategy to obtain the finer grid (with one extra grid step in between the ticks)? I actually do like that better than the rather coarse grid that we get in tinyplot.

And for the colors you would simply set palette.qualitative = c("#D18975", "#8FD175", "#3F2D54", "#75B8D1", "#2D543D", "#C9D175", "#D1AB75", "#D175B8", "#758BD1") in order to be self-contained? I would use that for "ipsum" but keep "Okabe-Ito" for "ipsum2".

P.S.: I will have to try writing code in my head at my next dentist visit. Not sure how successful that will be, though 😂

zeileis avatar May 21 '25 00:05 zeileis

The font business can be tricky. In the tinythemes I avoid dealing with "Arial Narrow" explicitly as hrbrthemes has "machinery" for it: so if it fails in the tiny variant, I suggest users rely on the infrastructure in the bigger package---from glancing at its help it seems that e.g. Windows users may have issues.

Overall this issue strikes the right tone: a closer variant is good to have, as is a simple variant.

eddelbuettel avatar May 21 '25 05:05 eddelbuettel

Thanks @eddelbuettel. I should look into the help docs a bit more there.

I also agree with Vincent that spacing would be important. Also, can we easily set a strategy to obtain the finer grid (with one extra grid step in between the ticks)? I actually do like that better than the rather coarse grid that we get in tinyplot.

I'll look into this @zeileis. It would also be cool if we could support a caption argument for these kinds of dynamic themes, in addition to main and sub.

grantmcdermott avatar May 21 '25 17:05 grantmcdermott