0

I have this plot command:

pdx_1990s_plot <- ggplot(pdx_disc_1990s, aes(year+(mon/12), vol)) +
    geom_bar(stat='identity', color='blue', fill='#0387fc', position='dodge') +
    theme_classic() +
    theme(plot.title = element_text(hjust = 0.5, face = 'bold')) +
    theme(plot.subtitle = element_text(hjust = 0.5, face = 'bold')) +
    ggtitle('Portland Monthly Mean Discharge', subtitle = '1988--1994') +
    xlab('Year') +
    ylab('Discharge (Cubic Feet/Second)')

which produces a plot with x-axis tics and their labels for each year.

I've not found how to have a small tic for each month and a larger tic for each year with the month names on one label line and the year labels on a second line underneath.

Please point me to a source for how to do this, with an example I can emulate.

TIA,

Rich

Rich Shepard
  • 109
  • 2
  • 10
  • 3
    Please see [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Provide your data via the output of `dput(pdx_disc_1990s)`. – AndrewGB Dec 22 '21 at 19:13
  • While `ggplot2` supports different tick lengths between sides, I think it does not support varying the tick lengths on the same side. I suspect (without verifying) that the intent of major/minor *grids* is intended to address this, though I don't think that's sufficient rationale (for me). – r2evans Dec 22 '21 at 19:27
  • ... though if you are not afraid of going elbow-deep (grob-modifying), try https://stackoverflow.com/q/20886498/3358272 – r2evans Dec 22 '21 at 19:29
  • @r2evans: Your cited thread changes the size of every other tick mark for a set of factors. What I would like, if possible, is adding tick marks for each month with the year underneath set of months for that year. The ticks would be the same size and the labels would be the month (3 characters) with the year underneath. – Rich Shepard Dec 22 '21 at 22:50
  • I've uploaded a copy of the plot. It will be available for 5 days at: . There should be a history of ggplot2 plots with months and years on the x-axis. – Rich Shepard Dec 22 '21 at 22:57
  • That doesn't quickly resolve to a png, and I (like some others here) are hesitant to click through too many links to get to an image. Please just upload it into your question via Stack's interface. However, I *do* understand what you are looking for. My point it this: ggplot2 does not allow for varying tick length on one side, so I think your only option is to vary every 12th tick based on factors (each year). – r2evans Dec 23 '21 at 10:29
  • @r2evans no major grid hack necessary, just use ggh4x :) https://teunbrand.github.io/ggh4x/reference/guide_axis_minor.html – tjebo Dec 23 '21 at 18:42
  • Rich, I think you might wanna have a look at https://stackoverflow.com/questions/20571306/multi-row-x-axis-labels-in-ggplot-line-chart, in particular the offered faceting option in the question itself – tjebo Dec 23 '21 at 18:48
  • @tjebo: thanks for the link to the multi-line labels thread. – Rich Shepard Dec 24 '21 at 20:07

1 Answers1

0

I understand that ggplot2 will not let me do what I want and I also decided to stick with what I have since the pattern of variability is more important than seeing a month name under each bar.

Thanks to both of you for responding and helping.

Happy holidays and stay safe.

Rich Shepard
  • 109
  • 2
  • 10