author: date: autosize: true
- Advanced layout
- Symbols (avoiding "expression/bquote hell")
- Papers vs talks vs posters
- Automated reports
- Python plotting (may have to wait till lab/next week)
- Multi-panel plots are in every paper.
- Where possible, I prefer to make each panel separately, so that LaTeX's subfigure environment allows cross-referencing.
- However, that strategy means MORE graphics files to upload to a journal, which sucks.
- So--panels, how to do them?
library(cowplot)
# library(ggplot2)
==============================
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
plot.mpg
==================
plot.diamonds <- ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
theme(axis.text.x = element_text(angle=70, vjust=0.5))
plot.diamonds
plot_grid(plot.mpg, plot.diamonds, labels = c("A", "B"))
plot_grid(plot.mpg, plot.diamonds, plot.diamonds, plot.mpg, labels=c("A","B","C","D"),ncol=2,rel_heights = c(0.5,1))
library(lattice)
library(grid)
library(gridExtra)
lattice.mpg = xyplot(hwy~cty,data=mpg,group=factor(cyl),auto.key=T)
combined = grid.arrange(lattice.mpg, plot.mpg,ncol=2)
grid.draw(combined)
===================================================
lattice.diamonds = histogram(~clarity|cut,data=diamonds)
lattice.diamonds
- Talks, posters,grants
- No one will spend 10 minutes going over your figures, so boil them down to the basics!
- Filter out the data for panels from the original.
dplyr
- Remove axis data from plots as appropriate
- Combine into one using
grid.arrange
,cowplot
, etc. - Generally, this involves "hacking" multiple existing plotting scripts into one.
- But this method is more reliable than Illustrator/Inkscape, and the new script documents exactly what you did!
A driver can look like this:
# Define the input file name that the template expects
infile <- 'data2.txt'
# Execute the template
rmarkdown::render("ReportTemplate.Rmd")
(Show the template...)
- littler will be your friend here.
- Pronounced "little r"
- Introduces proper scripting semantics to R OMG.
#!/usr/bin/env r
if(is.null(argv)) { stop("need some args") }
print("hi")
print(argv[1])
- Have your Python workflow generate any plots/tables and save them to files in a directory specified by the user
- Use
knitr
to render the report from anRmd
file that expects the directory name as a parameter. - You include the graphics using regular Markdown syntax.
For Jupyter notebooks, you have:
- papermill
- Officially, the Jupyter project views this as "outside the scope"
- Read more about pandoc and let me know if you find out anything!
library(reticulate)
use_python("/usr/bin/python3")
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.,2.,0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t,s)
plt.grid(True)
plt.show()
import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time")
g.map(plt.hist, "tip");
plt.show()
g = sns.FacetGrid(tips, col="sex", hue="smoker")
g.map(plt.scatter, "total_bill", "tip", alpha=.7)
g.add_legend();
plt.show()
for ax in g.axes.flat:
ax.set_title(r'$\Theta = \frac{\Gamma}{\sum_{i=1}{10}}$')
plt.show()