kaizadp / nmrrr

Binning and visualizing NMR spectra from environmental samples
Other
3 stars 2 forks source link

gg_spectra facets/stagger #8

Closed kaizadp closed 1 year ago

kaizadp commented 2 years ago

@bpbond

In the gg_spectra() function, we have an argument to stagger the spectra, so we can see multiple spectra at once. Works fine when we have just a single panel in the graph. But when I use facet_wrap, the staggering is weird (see pics). Is there a way we can "reset" the staggering, so it starts at 0 for each facet?

... or is this asking for too much from our package? It would be a cool feature, but we also don't want to break/bog down the functions with too many customizations.

image image

https://github.com/bpbond/nmrrr/blob/7c19c171deba6c697ccd32d02edaf76cf943181f/scratchpad.R#L32-L49

bpbond commented 2 years ago

Let's come back to this after #36 is merged.

bpbond commented 2 years ago

@kaizadp You're specifying (because the function needs) an absolute LABEL POSITION, but this needs to be group- (facet-) dependent. I would suggest changing LABEL_POSITION to nudge_y (following ggplot's geom_label parameter names). Then we can add that value to the max (e.g.) of each group. Hmm.

Another option would be to change this function to geom_spectra so that users can do something like

ggplot(dat, aes(x, y, label = lab)) + 
  geom_spectra(binset = Clemente, stagger = 0.5, nudge_y = 2) + 
  facet_wrap(~treatment)
kaizadp commented 2 years ago

Ooh, I like the idea of a geom_spectra. Don’t know how complicated that would be though.

kaizadp commented 2 years ago

I think we're thinking different things here. If we add facets, I'm ok keeping the label position an absolute value on the y-axis. My bigger concern is making sure the staggered spectra start at 0 for each facet.

I'm picturing something like this (I did this using patchwork, not facets). image

bpbond commented 2 years ago

Oh. I see. But does that have anything to do with nmr_plot_spectra? Aren't those intensity values assigned elsewhere?