` - defining table row
* `` - defining table column
Company |
Contact |
Country |
Alfreds Futterkiste |
Maria Anders |
Germany |
Centro comercial Moctezuma |
Francisco Chang |
Mexico |
# Figure in Two Columns
Arguments `out.width` and `out.height` apply to both existing images and R-generated figures.
Unlike the `fig.width` and `fig.height` arguments which only affect dynamic figures, the `out.width` and `out.height` arguments can be used with any type of graphic and conveniently can accept sizes in pixels or percentages as a string with % or px as a suffix.
Keep in mind that the % refers to the percent of the HTML container. For example, if the block of text that the image is in is 1000px wide then the image will be 200px using 20%.
`out.width` can also be used to lay out multi-column figures.
```{r out.width=c('50%', '50%'), fig.show='hold'}
boxplot(1:10)
plot(rnorm(10))
plot(density(rnorm(100)))
```
# Turn Sections to Tabs
Tab format HTML documents are sometimes easy for readers to read the document. R Markdown can convert section-format documents to tab-format documents easily. The following is a simple example based on the popular [R mtcars dataset](https://rstudio-pubs-static.s3.amazonaws.com/61800_faea93548c6b49cc91cd0c5ef5059894.html).
## An Example of Tab Format Document {.tabset .tabset-fade .tabset-pills}
### Scatter Plot
As an example, the following scatter plot shows the relationship between `gross horsepower` and `mile per gallon`.
```{r fig.align='center', fig.width=3, fig.height=3}
mtcars %>%
ggplot(aes(x = hp, y = mpg)) +
geom_point()
```
### Summary Table
The following summarized table gives the distributional information of the data set.
```{r}
#| collapse = FALSE
summary(mtcars)
```
# GIF Animation
R has several animation libraries one can use to generate animated graphs to explain some of the complex concepts visually. Sometimes people can generate a series of related images and then use software programs to make a GIF image. This external GIF can also be included in the R Markdown document.
```{r, animation.hook='gifski'}
for (i in 1:5) {
pie(c(i %% 5, 1, 3), col = c('red', 'yellow', "blue"), labels = paste(i))
}
```
# Load An External image
In addition to the R-generated graphics, we can also include external images in different formats in the R Markdown document. `out.width=` and `out.height=` options should be used to control the size of the images.
```{r, fig.align='center', out.width = "50%"}
include_graphics("https://editor.analyticsvidhya.com/uploads/75819stats_1050x520.png")
```
The following image was included using HTML tag ` `:
# Inline Chunk Options
If too many chunk options are required to lay out the figure, it is not convenient to put all of them in the code chunk. One way to handle this situation is to use inline chunk options.
```{r}
#| fig.width = 5, fig.height = 4,
#| fig.align='center', fig.cap = "My caption"
plot_ly(x=mtcars$wt,y=mtcars$mpg,mode = "markers",color = as.factor(mtcars$vs))
```
# Including CSS
There are three ways of inserting a style sheet in the RMarkdown document: inline CSS, internal CSS, and external CSS. We have used all three different formats of CSS in this RMD to format the text or decorate the layout on different occasions. To summarize,
* **inline CSS**: This is an example showing how to change the font size, face, color, etc.
* **internal CSS**: The internal CSS was included at YAML and setup code chunk ([Here Is the screenshot](https://pengdsci.github.io/STA490/w01/img/internalCSS.png))
* **External CSS**: The external CSS style file used in this document can be found ([here](https://pengdsci.github.io/STA490/w01/css/cpRMDstyle.css))
# Verbatim Code Chunks
Typically we write code chunks and inline expressions that we want to be parsed and evaluated by `knitr`. However, if we are trying to write a tutorial on using knitr`, we may need to generate a verbatim code chunk or inline expression that is not parsed by knitr, and we want to display the content of the chunk header and all related options.
````{verbatim}
```{r out.width=c('50%', '50%'), fig.show='hold'}
boxplot(1:10)
plot(rnorm(10))
plot(density(rnorm(100)))
```
````
|