Combining line graph and scatterplot for categorical and temporal data

I need to create a graph of interactions of a user with other users, hashtags, emojis, etc. on a temporal axis. I was thinking of combining a scatterplot for the main graph and then using a line graph to connect the points vertically. However, I am not sure how to approach it, since the data will be categorical and there is nothing numeric about it so I canโ€™t give it a y. Before I embark on this adventure, can someone tell me if this is doable? I know how to do the scatterplot part but am not sure about adding the line graph. Thank you!

Hi,

Welcome to the community!

It is not a problem for Plotly to have categorical data in one of the axis. Here is one example:

I think it is doable, perhaps not exactly as the picture that you posted. For example, if you want arrows for the lines, you must use annotations to do it, but then you canโ€™t control them together in the legendโ€ฆ If I were to build a chart like this,
I would like to use the legend to filter pairs at first, so I would use one trace per pair instead of individual plots and lines. For the direction, I would use different markers instead of an arrow, as it is not possible to do a line segment like this.

Here is a quick example of what I mean:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(
    go.Scatter(
        mode="lines+markers",
        name="A -> B",
        x=[
            "2021-01-20T08:23:00Z",
            "2021-01-20T08:23:00Z",
            None,
            "2021-01-20T08:28:00Z",
            "2021-01-20T08:28:00Z"
        ],
        y=[
            "a",
            "b",
            None,
            "a",
            "b"
        ]
    )
)


fig.add_trace(
    go.Scatter(
        mode="lines+markers",
        name="A -> C",
        x=[
            "2021-01-20T08:25:00Z",
            "2021-01-20T08:25:00Z",
        ],
        y=[
            "a",
            "c"
        ],
        marker_symbol=[
            "circle", 
            "circle-open"
        ]
    )
)

# Just adding an arrow as another option
fig.add_annotation(
    x="2021-01-20T08:26:00Z", 
    y="b",  
    ax="2021-01-20T08:26:00Z",
    ay="a", 
    xref='x',
    yref='y',
    axref='x',
    ayref='y',
    showarrow=True,
    arrowhead=4,
)

fig.show()

1 Like

Thank you for the warm welcome and thank you for the answer! This is exactly what I was looking for, Iโ€™ll test it out this weekend!