rmarkdown, chunk fig.show='hold'. - ggplot2 cars scatterplot. .
cars::scatterplot rmarkdown
PDF. out.width='3in' fig.height fig.width. fig.height fig.width, .
---
title: "Untitled"
author: "eipi10"
date: "November 23, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r fig.show='hold', out.width='3in', fig.height=5, fig.width=5}
library(car)
scatterplot(Sepal.Length~Sepal.Width|Species,data=iris,grid="FALSE",
boxplots="", reg.line="FALSE", pch=c(0,1,2))
scatterplot(Petal.Width~Sepal.Width|Species,data=iris,grid="FALSE",
boxplots="", reg.line="FALSE", pch=c(0,1,2))
```

ggplot2
ggplot2, :
library(ggplot2)
library(gridExtra)
theme_set(theme_bw())
grid.arrange(
ggplot(iris, aes(Sepal.Width, Sepal.Length, colour=Species)) +
geom_point() +
geom_smooth(alpha=0.2) +
theme(legend.position="top"),
ggplot(iris, aes(Sepal.Width, Petal.Width, colour=Species)) +
geom_point() +
geom_smooth(alpha=0.2) +
theme(legend.position="top"),
ncol=2)

ggplot2, cars::scatterplot output
. , se=FALSE geom_smooth. , aes(shape=Species) geom_point. , , + scale_shape_manual(values=0:2) .. .
, - .
my_theme = list(geom_point(aes(shape=Species)),
geom_smooth(se=FALSE, show.legend=FALSE, lwd=0.8),
scale_shape_manual(values=0:2),
scale_colour_manual(values=c("black", "red","green")),
theme_bw(),
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
legend.position="top"))
p1 = ggplot(iris, aes(Sepal.Width, Sepal.Length, colour=Species)) +
my_theme +
labs(x="Sepal Width", y="Sepal Length") +
scale_y_continuous(limits=c(3,8)) +
scale_x_continuous(limits=c(1,5))
p2 = ggplot(iris, aes(Sepal.Width, Petal.Width, colour=Species)) +
my_theme +
labs(x="Sepal Width", y="Petal Width")
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}
leg = g_legend(p1)
grid.arrange(leg,
arrangeGrob(grobs=lapply(list(p1,p2), function(p) p + guides(colour=FALSE, shape=FALSE)), ncol=2),
ncol=1, heights=c(1,10))
