orientation
¶Some geoms treat each axis differently and, thus, can have two orientations.
The orientation
parameter specifies the axis that the layer' stat and geom should run along (x-axis by default).
import numpy as np
import pandas as pd
from lets_plot import *
from lets_plot.mapping import as_discrete
LetsPlot.setup_html()
mpg = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
base = ggplot(mpg) + ggsize(800, 300)
manufacturer_mapping = as_discrete('manufacturer', order_by='..count..')
hide_x_label = theme(axis_title_x='blank')
hide_y_label = theme(axis_title_y='blank')
# orientation "x" (default) : "manufacturer" is mapped to the x-axis.
orientation_x = base + geom_bar(aes(x=manufacturer_mapping, fill='class'), color='white')
orientation_x + hide_x_label
orientation_x + coord_flip() + hide_x_label
# Orientation "y".
# The "manufacturer" is mapped to the y-axis.
base_y = base + hide_y_label
base_y + geom_bar(aes(y=manufacturer_mapping, fill='class'), color='white', orientation="y")
base_y + geom_boxplot(aes(y='manufacturer', x='cty'), width=0.7, orientation="y")
geom_violin()
¶ggplot(mpg) + geom_violin(aes(y="drv", x='cty', fill="drv"), trim=False, orientation="y") \
+ geom_boxplot(aes(y="drv", x='cty'), fill="white", alpha=0.5, width=0.3, orientation="y")
#
# Density estimates.
#
np.random.seed(0)
cov0=[[1, -.8],
[-.8, 1]]
cov1=[[ 10, .1],
[.1, .1]]
x0, y0 = np.random.multivariate_normal(mean=[-2,0], cov=cov0, size=200).T
x1, y1 = np.random.multivariate_normal(mean=[0,1], cov=cov1, size=200).T
data = dict(
x = np.concatenate((x0,x1)),
y = np.concatenate((y0,y1)),
c = ["A"]*200 + ["B"]*200
)
p = ggplot(data, aes("x", "y", color="c")) + geom_point()
p
geom_density()
¶p + geom_density(size=2)
p + geom_density(size=2, orientation="y")
geom_histogram()
¶p + geom_histogram(fill="rgba(0,0,0,0)")
p + geom_histogram(alpha=0, orientation="y", show_legend=False)
p + geom_freqpoly(size=2)
p + geom_freqpoly(size=2, orientation="y")
geom_smooth()
¶p + geom_smooth()
p + geom_smooth() + coord_flip()
p + geom_smooth(orientation="y")
geom_boxplot()
¶p + geom_boxplot(x=-10, color="black") \
+ geom_boxplot(y=-3, color="black", orientation="y")
geom_violin()
¶p + geom_violin(x=-10, color="black", alpha=0) \
+ geom_violin(y=-3, color="black", alpha=0, orientation="y")