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
2
votes
2 answers

S3 Methods: Extending ggplot2 `+.gg` function

I am trying to extend ggplot2 with a new class that we will call foo for this example. The goal is to write a +.foo method that will be used in place of +.gg. However I am running into an issue of "incompatible methods" The Setup Currently I am able…
Justin Landis
  • 1,981
  • 7
  • 9
2
votes
1 answer

How to set different width values in geom_split_violin?

It is known that the split violin plot could be plotted using geom_split_violin (Split violin plot with ggplot2). # Package library("ggplot2") # Function GeomSplitViolin <- ggproto("GeomSplitViolin", GeomViolin, …
Feng Tian
  • 1,559
  • 1
  • 18
  • 27
2
votes
1 answer

Extending ggplot2: How to build a geom and stat?

I am in the early stages of learning how to extend ggplot2. I would like to create a custom geom and associated stat. My starting point was the vignette. In addition, I have benefited from this and this. I'm trying to put together a template to…
PatrickT
  • 10,037
  • 9
  • 76
  • 111
2
votes
0 answers

Setting defaults by ggproto when extending ggplot2

I ran the R Code posted in http://ggplot2.tidyverse.org/articles/extending-ggplot2.html#picking-defaults and the following is the modified code that added some print() to show the values of variables in each step, my questions are marked as comments…
passiflora
  • 332
  • 1
  • 9
2
votes
2 answers

Constrict ggplot ellips to realistic/possible values

When plotting an ellips with ggplot is it possible to constrain the ellips to values that are actually possible? For example, the following reproducible code and data plots Ele vs. Var for two species. Var is a positive variable and cannot be…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
2
votes
1 answer

align points and error bars in ggplot when using `jitterdodge`

The reproducible data below contains 50 observations for each animal (cat and dog) for each season (Summer and Winter) for two covariates (cov1 and cov2) and their respective error estimates (SE). library(ggplot2); library(dplyr);…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
2
votes
1 answer

How to modify the backgroup color of label in the multiple-ggproto using ggplot2

I want to draw a graph which is familiar to the enterotype plot in the research. But my new multiple-ggproto seems terrible as showed in p1, owing to the missing backgroup color of the label. I've tried multiple variations of this, for example…
Dr Duck
  • 207
  • 3
  • 9
2
votes
1 answer

How to modify the legend of a plotting using ggproto function in ggplot2?

In principal component analysis, I extract component result in prcomp() for scatter plot. I want to add the labels of the group names, then the center of each groups is calculated in each groups using MASS::cov.trob(). I create new stat and rebuild…
Dr Duck
  • 207
  • 3
  • 9
2
votes
0 answers

Extending ggplot functionality with ggproto

This solution addresses how to extend ggplot functionality using ggproto, specifically on a boxplot example. I wonder how this approach might be generalised. For instance let's say I want to implement an algorithm to adjust the position of…
geotheory
  • 22,624
  • 29
  • 119
  • 196
2
votes
1 answer

ggplot2 change color of specific line from radar-chart

I have used the following example for my question: http://www.cmap.polytechnique.fr/~lepennec/R/Radar/RadarAndParallelPlots.html mtcarsscaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01)) mtcarsscaled$model <- rownames(mtcars) mtcarsmelted…
Stücke
  • 868
  • 3
  • 14
  • 41
2
votes
1 answer

Moving from proto to ggproto to create environments

I am using GeomBoxplotDark environment from ggplot2: Multiple color scales or shift colors systematically on different layers? However, ggplot2 moved away from proto to ggproto and so this doesn't work anymore. The specific code…
Borja
  • 63
  • 2
  • 6
2
votes
2 answers

Adding table to ggplot with facets

Reproducible code: x = sample(1:12,100,replace=TRUE) y = rnorm(100) z = sample(c('Sample A','Sample B'),100,replace=TRUE) d = data.frame(x,y,z) ggplot(data=d, aes(factor(x),y)) + geom_boxplot() + stat_summary(fun.y=mean, geom="line", aes(group=1),…
Divi
  • 1,614
  • 13
  • 23
2
votes
2 answers

plot a circle/convex hull arround a given percentage of points

I have x=rnorm(100) y=rnorm(100) plot(x,y) abline(h=0); abline(v=0) From point (0,0) and going outwards I would like to draw a contour/circle/ellipse/freehand convex hull that encloses any given percentage of points. Is there any function or…
ECII
  • 10,297
  • 18
  • 80
  • 121
1
vote
2 answers

How can I pass variables between ggplot personal functions?

I am trying to create some functions based on ggplot to create custom plots. The creation of functions is very easy and straight forward, but I cannot figure out the way to share information between the functions to help in the plot creation. Here…
teoten
  • 31
  • 1
  • 6
1
vote
1 answer

Enabling per-facet panel range clipping/cropping in ggplot2 for a factor variable, building on code that can do it for continuous x and y

Sometimes when plotting things in facets the default range doesn't give us the visualization we want, and specifying custom axes ranges would give us a much more interpretable image. I am trying to modify existing code that enables per-facet panel…
Stan Rhodes
  • 360
  • 2
  • 14