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.

add vertical line faceted chart

See original GitHub issue

Hello, I’m struggling with something that I can’t solve. let’s say we have the example from the Becker’s Barley Trellis Plot https://altair-viz.github.io/gallery/beckers_barley_trellis_plot.html What I want to do is add a dashed vertical line from x=30 so I can easily see if the value from the plots i over or under that value.

thanks!

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_point().encode(
    alt.X('median(yield)', scale=alt.Scale(zero=False)),
    alt.Y(
        'variety',
        sort=alt.EncodingSortField(field='yield', op='median', order='descending'),
        scale=alt.Scale(rangeStep=20)
    ),
    color='year:N',
    row='site'
)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

19reactions
uribe-converscommented, Sep 11, 2018

I was finally able to draw a vertical line on my Altair’s plots following the suggestions from above—thank you for that!—but I wonder if it would be possible to implement matplotlib’s hlines and vlines or something like ggplot’s + geom_vline(xintercept=2) too. It would make this library so much more intuitive and easy to use!

I do like the library very much and thank @jakevdp and the other contributors for the amazing job you have done with it. 🙌

2reactions
Mohammadreza20commented, Apr 29, 2021

Hello dear @vtnate for add a line to date in the chart, you should add the new rule to chart code. for shading read here

demo = alt.Chart(df).mark_line().encode(
alt.X("Time:T", title="Time of event"),
alt.Y('Temp:Q', title='Temp during event', scale=alt.Scale(domain=(65, 67))),

)

rules = alt.Chart(pd.DataFrame({
  'Date': ['2007-01-01 00:00:00', '2007-01-01 02:00:00',"2007-01-01 04:00:00"],
  'color': ['red', 'orange']
})).mark_rule().encode(
  x='monthdate(Date):T'#,
  #color=alt.Color('color:N', scale=None)
)

(demo + rules )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Different Line to Each Facet of ggplot2 Plot (R Example)
How to draw different lines to a ggplot2 facet plot in R - R programming example ... Currently, our plot does not contain...
Read more >
How to add different vertical lines on specific plots of the two ...
My question is how to add different vertical lines for different plots in the facets? For example, putting xintercept=c(10,20) on the left two ......
Read more >
How to create facets in vertical order using ggplot2 in R?
First of all, create a data frame. · Then, create facetted plot with facet_grid function. · After that, create the facetted plot with...
Read more >
How to create a faceted line-graph using ggplot2 in R
In ggplot2, geom_line() function is used to create a line graph. ... This will return vertical facets on the plot and to draw...
Read more >
Faceting with ggplot2 - The R Graph Gallery
facet_wrap() is the most common function for faceting with ggplot2 . It builds a new chart for each level of a categorical variable....
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