Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering facets #454

Closed
essicolo opened this issue Oct 6, 2021 · 1 comment
Closed

Ordering facets #454

essicolo opened this issue Oct 6, 2021 · 1 comment

Comments

@essicolo
Copy link

essicolo commented Oct 6, 2021

Hi,

Is there a way to order facets? For example, I load the daily minimum temperatures in Melbourne in the aim of plotting the temperature per month.

import numpy as np
import pandas as pd
import lets_plot as lp
lp.LetsPlot.setup_html()

temp = pd.read_csv("https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv")
temp.Date = pd.to_datetime(temp.Date)
temp = temp.assign(
    year = temp.Date.dt.year,
    month = temp.Date.dt.month_name(),
    day = temp.Date.dt.day
)

In R-ggplot, the ordering can be based on ordinal factors. So I ordered the month column.

from pandas.api.types import CategoricalDtype
months = pd.date_range(start='1900-01', freq='M', periods=12).month_name()
month_cat = CategoricalDtype(months, ordered=True)
temp = temp.assign(month = temp.month.astype(month_cat), year = temp.year.astype(str))

It seems that let's-plot doesn't consider the order.

lp.ggplot(temp, lp.aes(x = 'day', y = 'Temp')) +\
    lp.geom_line(lp.aes(colour = 'year')) +\
    lp.facet_wrap(facets = 'month')

Capture d’écran, le 2021-10-06 à 10 32 38

Edit: I used a better example with temperatures rather than CO2.

@alshan
Copy link
Collaborator

alshan commented Oct 6, 2021

Unfortunately you seem to be right: lets-plot ignores the original order and sorts values one way or another. Certainly must be fixed.
All you can do right now is to change values so what they are sorted in the desired order, i.e. : "January" --> "01-Jan" and so on.

@alshan alshan added this to the 2021Q4 milestone Oct 6, 2021
@alshan alshan closed this as completed in 51b5dbc Oct 21, 2021
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

No branches or pull requests

2 participants