Questions tagged [ggproto]

ggproto is at the heart of the R package ggplot2. It implements a protype based OO system which blurs the lines between classes and instances. It is inspired by the proto package, but it has some important differences. Notably, it cleanly supports cross-package inheritance, and has faster performance. Knowledge of ggproto is essential if you want to add new primitives, like geoms or stats to ggplot2.

Questions tagged with may often involve adding new functionality involved in plotting, such as making new scales, geoms, stats, coords and facet systems, through the ggproto extension mechanism.

The ggplot2 package introduced an official extension mechanism for Stats, Geoms and Positions in other packages in version 2.0.0. Since then, Facets (2.2.0) and Coords (3.0.0) were added. At the core of this mechanism is the prototype based ggproto class that define the parameters and methods with which different structures in ggplot2 are build.

Important introductions to the topic can be found here:

96 questions
6
votes
1 answer

Fontsize error when creating new Geom in ggplot2

I am trying to create a new geom that will create a wind radii chart from hurricane data. The data needed to run this came be generated from the following: storm_observation <- data_frame(longitude = c(-89.6, -89.6, -89.6), …
G.Ambrose
  • 219
  • 2
  • 7
6
votes
2 answers

ggplot2 2.0 new stat_ function: setting default scale for given aesthetics

I try to use the new functionality of ggplot2 in R that allows creating our own stat_ functions. I'm creating a simple one to compute and plot an interpolated surface between points arranged on a 2d array. I would like to create a stat_topo()…
Max
  • 298
  • 1
  • 9
5
votes
1 answer

Defining / modifying data for draw_key

This question came up on answering How to show arrows in backward and forward directions in a ggplot2 legend? I thought that a good way to automatically define the direction of the arrow in the glyph would be to pass this value, here "direction", as…
tjebo
  • 21,977
  • 7
  • 58
  • 94
5
votes
1 answer

When I modify a duplicated (copied) Geom object, this also modifies the underlying original Geom. Why?

When I modify parts of a duplicated Geom object, this also modifies the underlying original Geom. Why? (Big big thanks to user Stefan to identify this problem via comment on a now deleted previous question of…
tjebo
  • 21,977
  • 7
  • 58
  • 94
5
votes
1 answer

Modify spacing between key glyphs in vertical legend whilst keeping key glyph border

As a follow up to this famous thread. I decided to ask a new question because this is more specifically for vertical legends, and the given answers still don't provide a fully satisfactory solution. For polygon key glyphs, there was a suggestion to…
tjebo
  • 21,977
  • 7
  • 58
  • 94
5
votes
2 answers

Grouping with custom geom fails - how to inspect internal object from draw_panel()

This is a question related to a custom geom which is modified from this answer. The given geom failed with grouping, so I included coord_munch in draw_panel, much inspired by both GeomLine and GeomPath. It works actually in many cases, but I feel it…
tjebo
  • 21,977
  • 7
  • 58
  • 94
5
votes
1 answer

Passing an extra parameter to a custom geom in ggplot2

I am creating a custom geom and would like it to take an extra parameter, called showpoints, which does something or other to the actual plot. For example, by setting it to FALSE, the geom actually returns a zeroGrob(). I have found a way of doing…
January
  • 16,320
  • 6
  • 52
  • 74
5
votes
2 answers

ggplot2: change break points of discrete scale to be between two break points

I have the following dataset: df <- data.frame(dens = rnorm(5000), split = as.factor(sample(1:2, 5000, replace = T)), method = as.factor(sample(c("A","B"), 5000, replace = T)), counts = sample(c(1, 10, 100,…
user3236841
  • 1,088
  • 1
  • 15
  • 39
5
votes
2 answers

How to write a ggplot '+'-pipeable function that can refer to the input plot

I'm trying to write a function that can be called using the '+'-based ggplot2 syntax. myplot + myfunction Specifically, the function I'm writing symmetrizes the y-axis about zero, so it needs to determine the y-axis range for the input plot. So…
Russ Hyde
  • 2,154
  • 12
  • 21
5
votes
1 answer

Change geom_bar width default to another default

What I want to do I currently have a custom theme for my plots, and I want to have on top of that some predefined parameters for all type of plots. My first focus is on bar charts, where I want to change the default width. The default width of…
agatheblues
  • 229
  • 1
  • 10
5
votes
4 answers

Error: ScalesList was built with an incompatible version of ggproto

I'm doing a presentation in slidfy, using the deckjs framework. Everything was ok, but suddenly this chunk of code: ggplot(cars, aes(x = speed, y = dist)) + geom_point(color = 'red') + stat_smooth(method = "lm", formula = y ~ x, size = 0.5, se =…
Pablo
  • 613
  • 7
  • 11
5
votes
1 answer

In ggproto, coord$transform did not transform some columns to [0, 1]

I want to create a new Geom type: geom_ohlc(), which is something like Candlestick Charts, to plot the stock open-high-low-close data. After learning this Hadley's article: I tried this: GeomOHLC <- ggproto(`_class` = "GeomOHLC", `_inherit` =…
Jia Ru
  • 93
  • 6
5
votes
1 answer

Writing ggplot custom geometry function

I'm writing a function that creates ggplot's scatter plot with size of points representing the number of points with the same X and Y coordinates. I have a function that works: require(dplyr) plot_size_bubbles <- function(x,y) { dd =…
yuk
  • 19,098
  • 13
  • 68
  • 99
5
votes
2 answers

ggplot: percentile lines by group automation

I've found the dplyr %>% operator helpful with simple ggplot2 transformations (without resorting to ggproto, which is required for ggplot2 extensions), e.g. library(ggplot2) library(scales) library(dplyr) gg.histo.pct.by.group <- function(g, ...)…
Sim
  • 13,147
  • 9
  • 66
  • 95
5
votes
1 answer

Error in eval(expr, envir, enclos) : could not find function "eval"

I am working on the Kaggle Digit Recognizer problem.when I tried the given code I got the error. Error in eval(expr, envir, enclos) : could not find function "eval" library(ggplot2) library(proto) library(readr) train <-…