question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

layer then facet

See original GitHub issue

Hi Jake,

I followed your instructions here and got really close.

If you look at my example below, do you know a way to get the text marks to show the overall count on the x axis rather than for each colored segment? I’m sure I’m missing something obvious. visualization 18

import altair as alt
import pandas as pd

df=pd.DataFrame({'gender': ['male', 'male', 'male', 'female', 'female', 'other', 'other', 'female', 'female', 'female', 'male', 'male', 'female',  'other', 'other', 'female', 'male', 'male'], 
                 'grade': ['9-10', '11-12', '11-12', '9-10', '11-12', '9-10', '9-10', '9-10', '11-12', '11-12', '9-10', '11-12', '9-10', '9-10', '9-10', '9-10', '11-12', '11-12'], 
                 'like_school': ['yes', 'no', 'yes', 'neutral', 'neutral', 'no', 'yes', 'no', 'neutral', 'no', 'yes', 'no', 'yes', 'yes', 'neutral', 'neutral', 'no', 'yes']})

bars=alt.Chart().mark_bar().encode(
    y='like_school',
    x='count()',
    color='gender',
    tooltip=[alt.Tooltip('count()', title='number of records')]
).properties(
    width=180,
    height=180
)

text=bars.mark_text(color='black').encode(
    text='count()',
).properties(
    width=180,
    height=180
)

alt.layer(bars, text, data=df).facet(
    column='grade:N'  
)#.resolve_scale(color='independent')

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Alcampopianocommented, Sep 6, 2018

Okay, I was looking for this: im

Which is possible using the code above only if you define each chart separately. Sorry if I was not clear about what I was trying to accomplish.

df=pd.DataFrame({'gender': ['male', 'male', 'male', 'female', 'female', 'other', 'other', 'female', 'female', 'female', 'male', 'male', 'female',  'other', 'other', 'female', 'male', 'male'], 
                 'grade': ['9-10', '11-12', '11-12', '9-10', '11-12', '9-10', '9-10', '9-10', '11-12', '11-12', '9-10', '11-12', '9-10', '9-10', '9-10', '9-10', '11-12', '11-12'], 
                 'like_school': ['yes', 'no', 'yes', 'neutral', 'neutral', 'no', 'yes', 'no', 'neutral', 'no', 'yes', 'no', 'yes', 'yes', 'neutral', 'neutral', 'no', 'yes']})

bars=alt.Chart().mark_bar().encode(
    y='like_school',
    x='count()',
    color='gender',
    tooltip=[alt.Tooltip('count()', title='number of records')]
).properties(
    width=180,
    height=180
)

text=alt.Chart().mark_text(dx=10).encode(
    text='count()',
    y='like_school',
    x='count()',
).properties(
    width=180,
    height=180
)

alt.layer(bars, text, data=df).facet(
    column='grade:N'  
)
0reactions
Alcampopianocommented, Sep 6, 2018

Apologies for the confusion and thanks for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Facet layer basics | R - DataCamp
Here is an example of Facet layer basics: Faceting splits the data up into groups, according to a categorical variable, then plots each...
Read more >
17 Faceting - ggplot2: Elegant Graphics for Data Analysis
17 Faceting. You first encountered faceting in Section 2.5. Faceting generates small multiples each showing a different subset of the data.
Read more >
How do I facet by geom / layer in ggplot2? - Stack Overflow
Union (or rbind) the data frames together into one data frame. Then set up the ggplot and geoms and filter each geom for...
Read more >
Facets for ggplot2 Charts in R (Faceting Layer) - Finance Train
Faceting is a very useful visualization technique that allows you to create multiple versions of the same plot with multiple subsets of the...
Read more >
Facets
Likewise, facet_grid2() is based on ggplot2::facet_grid() and by default ... the layers is always such that the inner layers are closer to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found