marcboschmatas / ggspark

ggplot2 Functions to Create Tufte Style Sparklines
6 stars 0 forks source link

Possibility to add columns #1

Open xfim opened 1 month ago

xfim commented 1 month ago

Hola Marc,

M'ha encantat poder fer servir aquesta feina teva. Gràcies per posar-ho a disposició de tothom i per contribuir a R.

Obro aquest tema per demanar si seria possible, en l'esperit de la figura d'sparklines que hi ha al principi com a exemple de Tufte, d'afegir una opció que fos "facets" alguna cosa per dir-li que ho vols en 2/3/4 columnes ordenades per, per exemple, el número màxim de la sèrie al final del període. Seria molt útil, ja que ara cal fer-ho manualment.


Dear @marcboschmatas,

Would it be possible to have some sort of "facets" option to allow for 2/3/4 columns, in order to easily replicate Tufte's example that you start with? Thank you.

marcboschmatas commented 1 month ago

Ostres Xavier! M'alegro molt que t'hagi servit. Hi penso una mica a veure com ho puc implementar i, si més no, poso una vinyeta que expliqui com fer-ho si no trobo la manera. Curiositat, on ho has aplicat?

xfim commented 1 month ago

T'ho passo per correu (me'n dones un?). Gràcies per mirar-t'ho. Ja que hi estem posats, el tema de l'arrodoniment no em funciona. Obro un nou issue i ho fem seriosa i formalment?

marcboschmatas commented 1 month ago

mboschmatas@gmail.com. Si em pots fer un issue per això de l'arrodoniment i m'ho expliques bé, hi miro de fer un cop d'ull. Merci!

xfim commented 1 month ago

You could add a function like facet_sparklines(~ UnitOfObservation, ncol = 3, order = max) that would allow you to divide the figure in 3 columns by the Unit of observation traced over time, and to also allow the units to be sorted by their maximum value attained during the series.

marcboschmatas commented 1 month ago

I wonder if this could be solved just by using facet_wrap and specifying the number of columns instead of facet_grid as proposed in the vignette, or ad a second variable to the facet_grid. Something like this


  stat_interquartilerange(geom = "ribbon",
                          show.legend = FALSE) +
  geom_line() + 
  stat_sparklabels(geom = "point", label_fun = \(x) round(x, 0),
                   show.legend = FALSE) + 
  stat_sparklabels(geom = "text_repel", label_fun = \(x) round(x, 2),
                   show.legend = FALSE) + 
  scale_colour_manual("", values = c("black", "blue", "red")) + 
  scale_y_continuous(limits = c(0, 25)) + 
  facet_wrap(~Month, ncol = 2) +
  ggtitle("Daily wind intensity by month in NYC") +
  theme_minimal() + 
  theme(panel.grid = element_blank(),
        axis.ticks = element_line())```
xfim commented 1 month ago

Partially. And it is true that Tufte's example in the beginning has the column sorted left-to-right and then down to bottom. But I was wondering if it would be better to see them top-down and then left-to-right. Which requires a different set up from the already existing facet_ functions. I am not sure how Tufte would approach it. If you don't see it, just let it go.

marcboschmatas commented 1 month ago

I put it on my to-do list. I don't know if I'll be able to do it as soon as I'd like to but it's definitely on my mind.