Skip to content

Gallery: Barplots and time series line plots#634

Open
zeileis wants to merge 8 commits into
mainfrom
gallery-ipcc
Open

Gallery: Barplots and time series line plots#634
zeileis wants to merge 8 commits into
mainfrom
gallery-ipcc

Conversation

@zeileis

@zeileis zeileis commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Follow up to the discussion in #631

I've added two more time series displays:

  • IPCC climate projection with direct labels. The entire IPCC data (rounded to three decimal places) is in the code - I hope this isn't too much?
  • EuStockMarkets time series with four panels. For now this is done by manually turning the ts into a long data.frame. We could switch to the ts method once this is in main.

And two barplots:

  • A simple one with rotated axis labels based on our 2026 FIFA World Cup forecast. But I'm happy to switch to something else if you feel that this is too much of a plug.
  • A more complex one for the penguins data.

@zeileis

zeileis commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

I haven't debugged why altdoc fails here...possibly because of using colorspace without declaring it? I rendered the altdoc successfully locally.

@grantmcdermott

Copy link
Copy Markdown
Owner

The GitHub CI has been acting up all day. I don't know why and I'm surprised that it hasn't been resolved yet. https://bsky.app/profile/gmcd.bsky.social/post/3molwkrctoc2i

I switched over to a more efficient CI workflow in #633 and this seems to be working well for R CMD check... But the altdoc workflow is still too slow for my liking. Do you mind fetching this latest update from the main branch and then running git merge main on your local PR branch? That should hopefully resolve some of the issues.

@zeileis

zeileis commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

I started out from the latest main branch so there seems to be nothing to fetch here...

I now tried to replace colorspace::lighten by tinyplot:::seq_palette just to see whether this runs successfully. If so, we can discuss options. If not, we can have a closer look at the GHA.

@zeileis

zeileis commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

Ok, failed again but at a different point in the GHA. So it seems that the GHA itself needs to be improved and the we need to tell it to install colorspace as well. 🧐

@grantmcdermott

grantmcdermott commented Jun 19, 2026

Copy link
Copy Markdown
Owner

I just triggered a re-run and it worked. Again, I think certain GHA are just being very flakey at the moment. 🤷‍♂️

RE: colorspace. I think we'd have to declare it in Suggests, no?

@zeileis

zeileis commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

Yes, adding colorspace to DESCRIPTION/Suggests worked and the GHA was kind enough to run successfully 😇

@grantmcdermott

Copy link
Copy Markdown
Owner

This is great, thanks @zeileis. I've been going through these locally and have made a few minor tweaks (which I'll share soon and hope you don't mind).

The one plot that I'm not wild about, though is barplot-penguins.R. I get the functionality that you're demonstrating, but I just don't think the end plot is particularly aesthetically pleasing. (Sorry!)

Would you mind if I replaced it with something simple like:

plt(
   Freq ~ Dept | Admit + Gender,
   data = as.data.frame(UCBAdmissions),
   type = "barplot",
   beside = TRUE,
   legend = list("bottom!", title = NULL),
   theme = "broadsheet", palette = "paired"
)

?

@grantmcdermott

Copy link
Copy Markdown
Owner

P.S. One stronger tweak that I didn't make, but would like your thoughts on, was adding (drawing) some annotations on the IPCC plot.

ipcc = data.frame(
  scenario = rep(c("", "SSP1 - 1.9", "SSP1 - 2.6", "SSP2 - 4.5", "SSP3 - 7.0", "SSP5 - 8.5"), c(65, 85, 85, 85, 85, 85)), 
  year = c(1950:2014, rep(2015:2099, 5)), 
  temperature = c(
    0.252, 0.275, 0.274, 0.253, 0.246, 0.273, 0.270, 0.268, 0.259, 0.258, 0.276, 0.279, 0.243, 0.146, 0.068, 0.089, 0.137, 0.132, 0.163, 0.198, 0.212, 0.229,
    0.203, 0.226, 0.247, 0.212, 0.220, 0.278, 0.282, 0.311, 0.347, 0.378, 0.337, 0.232, 0.303, 0.355, 0.388, 0.438, 0.472, 0.516, 0.586, 0.565, 0.292, 0.348,
    0.450, 0.491, 0.566, 0.638, 0.646, 0.682, 0.735, 0.799, 0.820, 0.856, 0.866, 0.884, 0.899, 0.929, 0.943, 0.962, 1.003, 1.036, 1.061, 1.085, 1.100,
    1.099, 1.123, 1.149, 1.175, 1.201, 1.225, 1.252, 1.277, 1.300, 1.321, 1.344, 1.367, 1.388, 1.407, 1.426, 1.444, 1.459, 1.474, 1.488, 1.499, 1.510, 1.520,
    1.528, 1.535, 1.543, 1.550, 1.554, 1.559, 1.563, 1.566, 1.568, 1.567, 1.567, 1.567, 1.566, 1.565, 1.565, 1.563, 1.561, 1.560, 1.557, 1.553, 1.550, 1.547,
    1.544, 1.540, 1.537, 1.533, 1.529, 1.525, 1.521, 1.518, 1.514, 1.511, 1.507, 1.503, 1.499, 1.496, 1.492, 1.489, 1.487, 1.483, 1.479, 1.475, 1.469, 1.464,
    1.459, 1.455, 1.451, 1.447, 1.444, 1.439, 1.434, 1.430, 1.424, 1.418, 1.414, 1.411, 1.407, 1.403, 1.400, 1.396, 1.392, 1.388, 1.385,
    1.099, 1.125, 1.151, 1.177, 1.202, 1.229, 1.254, 1.279, 1.302, 1.325, 1.351, 1.373, 1.396, 1.417, 1.440, 1.461, 1.480, 1.499, 1.518, 1.534, 1.550, 1.565,
    1.579, 1.595, 1.610, 1.622, 1.635, 1.648, 1.660, 1.670, 1.680, 1.691, 1.700, 1.708, 1.716, 1.724, 1.733, 1.740, 1.747, 1.754, 1.760, 1.766, 1.770, 1.774,
    1.778, 1.783, 1.786, 1.788, 1.792, 1.795, 1.797, 1.799, 1.799, 1.799, 1.801, 1.801, 1.800, 1.801, 1.800, 1.799, 1.799, 1.798, 1.796, 1.794, 1.792, 1.789,
    1.787, 1.784, 1.781, 1.778, 1.775, 1.772, 1.769, 1.764, 1.761, 1.759, 1.754, 1.750, 1.746, 1.742, 1.739, 1.735, 1.732, 1.727, 1.724,
    1.103, 1.127, 1.152, 1.177, 1.203, 1.230, 1.256, 1.281, 1.307, 1.333, 1.358, 1.381, 1.406, 1.433, 1.458, 1.483, 1.506, 1.529, 1.551, 1.573, 1.594, 1.617,
    1.641, 1.665, 1.689, 1.712, 1.737, 1.762, 1.787, 1.809, 1.831, 1.855, 1.880, 1.902, 1.922, 1.946, 1.973, 1.994, 2.017, 2.039, 2.061, 2.084, 2.104, 2.125,
    2.146, 2.165, 2.186, 2.205, 2.225, 2.245, 2.263, 2.281, 2.298, 2.316, 2.334, 2.350, 2.366, 2.386, 2.401, 2.421, 2.437, 2.449, 2.469, 2.485, 2.499, 2.513,
    2.527, 2.542, 2.557, 2.572, 2.586, 2.601, 2.614, 2.627, 2.639, 2.650, 2.665, 2.675, 2.687, 2.698, 2.710, 2.721, 2.730, 2.740, 2.748,
    1.094, 1.118, 1.143, 1.170, 1.195, 1.220, 1.247, 1.273, 1.299, 1.324, 1.349, 1.376, 1.403, 1.432, 1.460, 1.488, 1.517, 1.546, 1.574, 1.602, 1.630, 1.660,
    1.691, 1.720, 1.749, 1.781, 1.815, 1.847, 1.876, 1.908, 1.940, 1.974, 2.006, 2.037, 2.066, 2.101, 2.133, 2.167, 2.200, 2.235, 2.268, 2.300, 2.334, 2.368,
    2.404, 2.439, 2.473, 2.510, 2.547, 2.584, 2.622, 2.659, 2.696, 2.730, 2.765, 2.799, 2.837, 2.876, 2.912, 2.950, 2.987, 3.028, 3.066, 3.102, 3.141, 3.181,
    3.218, 3.254, 3.293, 3.332, 3.371, 3.409, 3.448, 3.490, 3.530, 3.568, 3.606, 3.645, 3.684, 3.721, 3.758, 3.796, 3.835, 3.872, 3.909,
    1.110, 1.137, 1.166, 1.195, 1.224, 1.254, 1.283, 1.316, 1.347, 1.377, 1.410, 1.442, 1.475, 1.509, 1.544, 1.577, 1.610, 1.644, 1.678, 1.713, 1.748, 1.783,
    1.818, 1.854, 1.892, 1.933, 1.973, 2.011, 2.052, 2.094, 2.136, 2.178, 2.219, 2.261, 2.304, 2.348, 2.393, 2.439, 2.486, 2.531, 2.573, 2.619, 2.668, 2.713,
    2.757, 2.797, 2.845, 2.893, 2.942, 2.989, 3.036, 3.086, 3.135, 3.181, 3.229, 3.280, 3.329, 3.376, 3.426, 3.478, 3.528, 3.579, 3.630, 3.679, 3.734, 3.784,
    3.833, 3.886, 3.939, 3.990, 4.042, 4.093, 4.145, 4.198, 4.249, 4.300, 4.351, 4.402, 4.451, 4.499, 4.549, 4.597, 4.644, 4.690, 4.735))

library("tinyplot")
tinyplot(
  temperature ~ year | scenario,
  data = ipcc,
  type = "l",
  theme = "socviz",
  col = c("#000000", "#00a9d1", "#29416e", "#e58c35", "#dd4048", "#942324"),
  lwd = 3,
  grid = "xY",
  legend = "direct",
  main = "Global surface temperature change relative to 1850-1900",
  sub = "Intergovernmental Panel on Climate Change (IPCC), Sixth Assessment Report",
  xlab = "",
  ylab = "Temperature change [°C]",
  draw = {
    abline(v = 2014.5, lty = 2)
    text(2014, 0, "Historic", pos = 2)
    text(2015, 0, "Forecast", pos = 4)
  }
)

Created on 2026-06-20 with reprex v2.1.1

What do you think? (Feel free to dismiss!)

@zeileis

zeileis commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator Author

The IPCC suggestion is nice - both in terms of displayed information and tinyplot functionality. I've added this with two small tweaks: Gray instead of black, projection instead of forecast.


I used the penguins example because the absolute frequencies are of interest and because the palmerpenguins documentation has a similar example.

But we can surely find another example, I'll try to think about something.


I don't think that the UCB admissions barplot is useful. It focuses on the joint distribution of admission/reject and department/gender which obscures the main insights in the data. What viewers should be able to see easily:

  • Admission/rejection rates differ across departments: Rejections are rather low for departments A and B.
  • Admission/rejection rates are very similar for both genders across departments A to F.
  • Females apply rarely at departments A and B.
  • If there is any discrimination, then females are admitted more frequently in department A.

That means we should focus on the conditional distribution of admission/rejection given department/gender. Additionally, the marginal distribution of department/gender is of interest. This is exactly what spineplots (aka mosaic displays, doubledecker plots, etc.) are designed for. Here, we can use:

ucb <- UCBAdmissions |>
  as.data.frame() |>
  transform(DeptGender = factor(paste(Dept, Gender, sep = ":\n")))

tinyplot(
  Admit ~ DeptGender,
  data = ucb,
  type = type_spineplot(weights = ucb$Freq)
)
tinyplot-ucb

@grantmcdermott

Copy link
Copy Markdown
Owner

Makes sense, thanks!

Maybe I should just get on board with the penguins example. Let me think on it...

(OTOH if we want a canonical grouped barplot display for the gallery, maybe something simple will do.)

FWIW, I just pushed my other minor tweaks for you to take a look at. For example, I simplified the spacing and theme customization for barplot-fifa2026.R, so that it uses less code and should fit the margins better. Let me know if you have any objections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants