geom_path()
and geom_line()
¶Using size
and color
aesthetics in the mapping of geom_path
or geom_line
may lead to variadic width or/and color of lines, depending on the data.
import pandas as pd
from lets_plot import *
from lets_plot.mapping import as_discrete
LetsPlot.setup_html()
airquality = pd.read_csv("https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/airquality.csv")
airquality.head()
Unnamed: 0 | Ozone | Solar.R | Wind | Temp | Month | Day | |
---|---|---|---|---|---|---|---|
0 | 1 | 41.0 | 190.0 | 7.4 | 67 | 5 | 1 |
1 | 2 | 36.0 | 118.0 | 8.0 | 72 | 5 | 2 |
2 | 3 | 12.0 | 149.0 | 12.6 | 74 | 5 | 3 |
3 | 4 | 18.0 | 313.0 | 11.5 | 62 | 5 | 4 |
4 | 5 | NaN | NaN | 14.3 | 56 | 5 | 5 |
ggplot(airquality) \
+ geom_line(
aes(
x = 'Day',
y = 'Temp',
size = 'Wind', # <--- wind varies by day
color = as_discrete('Month')
)
) \
+ scale_size([0.5, 5.0]) \
+ ggsize(700, 500)
ggplot(airquality) \
+ geom_line(
aes(
x = 'Day',
y = 'Temp',
color = 'Wind', # <--- wind varies by day
group = 'Month'
),
size=2
) \
+ scale_color_gradient(low='#1a9641', high='#d7191c') \
+ ggsize(700, 500)
ggplot(airquality) \
+ geom_line(
aes(
x = 'Day',
y = 'Temp',
color = 'Ozone', # <--- ozone varies by day and sometimes n/a
size = 'Wind', # <--- wind varies by day
group = 'Month'
)
) \
+ scale_size([0.5, 5.0]) \
+ scale_color_brewer(palette = "RdYlGn", direction = -1) \
+ ggsize(700, 500)
The orirnal can be found here: https://en.wikipedia.org/wiki/Charles_Joseph_Minard#The_map_of_Napoleon%27s_Russian_campaign
minard = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/minard/troops.csv')
minard.head()
long | lat | survivors | direction | group | |
---|---|---|---|---|---|
0 | 24.0 | 54.9 | 340000 | A | 1 |
1 | 24.5 | 55.0 | 340000 | A | 1 |
2 | 25.5 | 54.5 | 340000 | A | 1 |
3 | 26.0 | 54.7 | 320000 | A | 1 |
4 | 27.0 | 54.8 | 300000 | A | 1 |
ggplot(minard) \
+ geom_livemap() \
+ geom_path(aes(x='long', y='lat', size='survivors', group='group', color='direction')) \
+ scale_size([1.0, 20.0]) \
+ scale_color_manual(["#E1CBAE", "#232021"]) \
+ guides(color = "none")