Last active
June 30, 2022 19:46
-
-
Save jennybc/e9e9aba6ba18c72cec26 to your computer and use it in GitHub Desktop.
Quicky and dirty: side-by-side plot and table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Quicky and dirty: side-by-side plot and table" | |
author: "Omar AlOmeir" | |
output: | |
html_document: | |
css: two_columns.css | |
--- | |
Code from Omar AlOmeir, posted by Jenny Bryan | |
See <a href="https://gist.github.com/jennybc/e9e9aba6ba18c72cec26#file-2015-03-02_plot-next-to-table-rmd" target='_blank'>this Gist</a> for the code. | |
See [this RPub](http://rpubs.com/jennybc/plot-next-to-table) for the rendered HTML. | |
```{r} | |
library(ggplot2) | |
suppressMessages(library(dplyr)) | |
#devtools::install_github("jennybc/gapminder") | |
library("gapminder") | |
gtbl <- tbl_df(gapminder) | |
``` | |
<div class="twoC"> | |
```{r results = 'asis', echo=FALSE} | |
tbl1 <- gtbl %>% | |
group_by(continent) %>% | |
summarise_each(funs(mean, median), gdpPercap) | |
knitr::kable(tbl1) | |
``` | |
```{r echo=FALSE} | |
ggplot(gtbl, aes(x = continent, y = gdpPercap, color = continent)) + | |
geom_point() + ggtitle("GDP per cap by continent") | |
``` | |
</div> | |
<div class="clearer"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.twoC {width: 100%} | |
.clearer {clear: both} | |
.twoC .table {max-width: 50%; float: right} | |
.twoC img {max-width: 50%; float: left} |
I gather this came from stack overflow? Not sure? But I'd be happy to link to the original source if someone knows.
More hackage: put this directly in the Rmd:
<style type="text/css">
.twoC {width: 100%}
.clearer {clear: both}
.twoC .table {max-width: 50%; float: right}
.twoC img {max-width: 50%; float: left}
</style>
It looks like this only works for html output? I would like to place a table and a plot side by side in a pdf document. Any suggestions? I can accomplish this using tableGrob but would prefer to use kable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my table is messy then , bad luck?