layer then facet
See original GitHub issueHi 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.
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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, I was looking for this:
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.
Apologies for the confusion and thanks for the help.