Skip to content

Schmytzi/simplePlotTable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simplePlotTable

This package provides a way of drawing a table with ggplot2, using geom_text, only. The main purpose is to make tables easy to align using e.g. patchwork or cowplot and use them as axis labels. I want to keep styling options to a minimum (i.e. aesthetics available to geom_text), so no further options are planned. However, you can add additional elements to the table, as it is a simple plot with continuous coordinates.

Installation

devtools::install_github("Schmitzi/simplePlotTable")

Examples

Basic Output

library(simplePlotTable)
library(ggplot2)

# Using mtcars for demonstration
data <- mtcars[1:10, c("wt", "mpg", "cyl")]

# Create object
tbl <- new_SimplePlotTable(data[, c("cyl", "wt")])

tbl_plot <- autoplot(tbl)
tbl_plot

Basic Output Example

Styling

library(magrittr)

tbl %>%
  set_style(hjust=1) %>%
  set_style(cols=2, fontface="italic") %>%
  set_style(cols=1, rows=4, colour="red") %>% 
  set_column_header_style(face="bold") %>% 
  set_row_header_style(face="italic", hjust=1) %>% 
  autoplot()

Styling Example

Alignment to Other Plots

library(patchwork)

# Adding factor with cars for ggplot, preserves order
data$car <- factor(rownames(data), levels=rownames(data))

mpg_plot <- ggplot(data) +
  geom_col(aes(x=car, y=mpg)) +
  theme_classic() + 
  theme(axis.text.y = element_blank(), axis.title.y=element_blank()) +
  coord_flip()
  
(tbl_plot | mpg_plot) + plot_layout(widths=c(1,3))

Alignment Example

Why?

I found existing solutions, like gridExtra's tableGrob, too annoying to use, especially when I tried to align them to plots. There are definitely a lot more customizable options out there. This packages goal is not to be a full-fledged system for table creation in ggplot. It is supposed to make it as easy as possible to draw a simple table in ggplot2 and align it to an axis.

About

A simple table to include in ggplot

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Languages