import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
mpg = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg
p = (
ggplot(mpg, aes('displ', 'hwy')) +
geom_point() +
labs(
title = "Fuel efficiency\nfor most popular models of car",
subtitle = "Period 1999-2008",
caption = "MPG Dataset",
x="Engine displacement\n(litres)",
y = "Highway\nmiles per gallon"
) +
theme_classic() +
theme(plot_background=element_rect(size=1))
)
p
# Change margins around plot title, subtitle, caption and axis titles
p + theme(plot_title=element_text(margin=margin(t=15)),
plot_subtitle=element_text(margin=margin(b=10)),
plot_caption=element_text(margin=margin(b=15)),
axis_title_x=element_text(margin=margin(t=10)),
axis_title_y=element_text(margin=margin(r=10, l=15)))
# Change margins around axis tick labels
p + theme(axis_text_x=element_text(margin=margin(t=10, b=15)),
axis_text_y=element_text(margin=margin(r=10, l=15)))
# axis labels at different levels
p2 = ggplot(mpg, aes('class', 'hwy')) + geom_boxplot()
p2
p2 + theme(axis_text_x=element_text(margin=margin(t=10, b=10)))
# with rotation
p2 + ggsize(550, 400)
p2 + ggsize(550, 400)+ theme(axis_text_x=element_text(margin=margin(t=10)))