@ -0,0 +1,73 @@ |
|||||
|
# Generated by roxygen2: do not edit by hand |
||||
|
|
||||
|
S3method(grid.draw,absoluteGrob) |
||||
|
S3method(grobHeight,absoluteGrob) |
||||
|
S3method(grobWidth,absoluteGrob) |
||||
|
S3method(grobX,absoluteGrob) |
||||
|
S3method(grobY,absoluteGrob) |
||||
|
export(CoordProj) |
||||
|
export(Gb) |
||||
|
export(GeomBkde) |
||||
|
export(GeomBkde2d) |
||||
|
export(GeomEncircle) |
||||
|
export(GeomStateface) |
||||
|
export(GeomTable) |
||||
|
export(GeomXSpline2) |
||||
|
export(GeomXspline) |
||||
|
export(Kb) |
||||
|
export(Mb) |
||||
|
export(StatAsh) |
||||
|
export(StatBkde) |
||||
|
export(StatBkde2d) |
||||
|
export(StatXspline) |
||||
|
export(byte_format) |
||||
|
export(bytes) |
||||
|
export(coord_proj) |
||||
|
export(geom_bkde) |
||||
|
export(geom_bkde2d) |
||||
|
export(geom_encircle) |
||||
|
export(geom_stateface) |
||||
|
export(geom_xspline) |
||||
|
export(list_avatars) |
||||
|
export(load_stateface) |
||||
|
export(pokemon_pal) |
||||
|
export(scale_color_pokemon) |
||||
|
export(scale_colour_pokemon) |
||||
|
export(scale_fill_pokemon) |
||||
|
export(show_stateface) |
||||
|
export(stat_ash) |
||||
|
export(stat_bkde) |
||||
|
export(stat_bkde2d) |
||||
|
export(stat_xspline) |
||||
|
import(KernSmooth) |
||||
|
import(MASS) |
||||
|
import(ash) |
||||
|
import(ggplot2) |
||||
|
import(grDevices) |
||||
|
import(graphics) |
||||
|
import(maps) |
||||
|
import(proj4) |
||||
|
importFrom(RColorBrewer,brewer.pal) |
||||
|
importFrom(dplyr,filter) |
||||
|
importFrom(extrafont,fonts) |
||||
|
importFrom(extrafont,loadfonts) |
||||
|
importFrom(extrafont,ttf_import) |
||||
|
importFrom(grid,gList) |
||||
|
importFrom(grid,gTree) |
||||
|
importFrom(grid,gpar) |
||||
|
importFrom(grid,grid.draw) |
||||
|
importFrom(grid,grobHeight) |
||||
|
importFrom(grid,grobName) |
||||
|
importFrom(grid,grobTree) |
||||
|
importFrom(grid,grobWidth) |
||||
|
importFrom(grid,grobX) |
||||
|
importFrom(grid,grobY) |
||||
|
importFrom(grid,textGrob) |
||||
|
importFrom(grid,unit.c) |
||||
|
importFrom(grid,viewport) |
||||
|
importFrom(gtable,gtable_col) |
||||
|
importFrom(gtable,gtable_height) |
||||
|
importFrom(gtable,gtable_row) |
||||
|
importFrom(gtable,gtable_width) |
||||
|
importFrom(scales,expand_range) |
||||
|
importFrom(scales,rescale) |
@ -0,0 +1,94 @@ |
|||||
|
#' @rdname ggalt-ggproto |
||||
|
#' @format NULL |
||||
|
#' @usage NULL |
||||
|
#' @export |
||||
|
GeomTable <- ggproto( |
||||
|
"GeomTable", |
||||
|
Geom, |
||||
|
required_aes = c("x", "y", "table"), |
||||
|
default_aes = aes( |
||||
|
widthx = 10, |
||||
|
widthy = 10, |
||||
|
rownames = NA |
||||
|
), |
||||
|
draw_key = draw_key_blank, |
||||
|
|
||||
|
draw_panel = function(data, panel_scales, coord) { |
||||
|
if (nrow(data) != 1) { |
||||
|
stop( |
||||
|
sprintf( |
||||
|
"only one table per panel allowed, got %s (%s)", |
||||
|
nrow(data), |
||||
|
as.character(data) |
||||
|
), |
||||
|
call. = FALSE |
||||
|
) |
||||
|
} |
||||
|
wy = data$widthy / 2 |
||||
|
wx = data$widthx / 2 |
||||
|
|
||||
|
corners <- |
||||
|
data.frame(x = c(data$x - wx, data$x + wx), |
||||
|
y = c(data$y - wy, data$y + wy)) |
||||
|
d <- coord$transform(corners, panel_scales) |
||||
|
|
||||
|
# gross hack, but I've found no other way to get a table/matrix/dataframe to this point :-( |
||||
|
table = read.csv(text = data$table, header = TRUE) |
||||
|
if (!is.na(data$rownames)) { |
||||
|
rownames(table) <- |
||||
|
unlist(strsplit(data$rownames, "|", fixed = TRUE)) |
||||
|
} |
||||
|
|
||||
|
x_rng <- range(d$x, na.rm = TRUE) |
||||
|
y_rng <- range(d$y, na.rm = TRUE) |
||||
|
|
||||
|
vp <- |
||||
|
viewport( |
||||
|
x = mean(x_rng), |
||||
|
y = mean(y_rng), |
||||
|
width = diff(x_rng), |
||||
|
height = diff(y_rng), |
||||
|
just = c("center", "center") |
||||
|
) |
||||
|
|
||||
|
grob <- |
||||
|
tableGrob(table, theme = ttheme_minimal()) |
||||
|
# add a line across the header |
||||
|
grob <- gtable_add_grob( |
||||
|
grob, |
||||
|
grobs = segmentsGrob(y1 = unit(0, "npc"), |
||||
|
gp = gpar(lwd = 2.0)), |
||||
|
t = 1, |
||||
|
b = 1, |
||||
|
l = 1, |
||||
|
r = ncol(d) + 1 |
||||
|
) |
||||
|
editGrob(grob, vp = vp, name = paste(grob$name, facet_id())) |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
facet_id <- local({ |
||||
|
i <- 1 |
||||
|
function() { |
||||
|
i <<- i + 1 |
||||
|
i |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
#' Add a table to a ggplot2 plot |
||||
|
#' |
||||
|
#' @author Jan Schulz |
||||
|
geom_table <- function(mapping = NULL, data = NULL, stat = "identity", |
||||
|
position = "identity", na.rm = FALSE, |
||||
|
show.legend = NA, inherit.aes = TRUE, ...) { |
||||
|
layer( |
||||
|
geom = GeomTable, |
||||
|
mapping = mapping, |
||||
|
data = data, |
||||
|
stat = stat, |
||||
|
position = position, |
||||
|
show.legend = show.legend, |
||||
|
inherit.aes = inherit.aes, |
||||
|
params = list(na.rm = na.rm, ...) |
||||
|
) |
||||
|
} |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 83 KiB |
After Width: | Height: | Size: 83 KiB |
@ -0,0 +1,17 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/geom_table.r |
||||
|
\name{geom_table} |
||||
|
\alias{geom_table} |
||||
|
\title{Add a table to a ggplot2 plot} |
||||
|
\usage{ |
||||
|
geom_table(mapping = NULL, data = NULL, stat = "identity", |
||||
|
position = "identity", na.rm = FALSE, show.legend = NA, |
||||
|
inherit.aes = TRUE, ...) |
||||
|
} |
||||
|
\description{ |
||||
|
Add a table to a ggplot2 plot |
||||
|
} |
||||
|
\author{ |
||||
|
Jan Schulz |
||||
|
} |
||||
|
|