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
4
votes
1 answer

Can't apply scale_x_log10() to my own geom: it appears on plot incorrectly

I'm trying to understand how ggproto works to write my own geoms. I wrote geom_myerrorbarh (analogous to geom_errorbarh, but only with x,y, xwidth arguments). The figure below shows that everything works correctly at a linear scale. However, if you…
4
votes
1 answer

Building a new geom_hurricane

I have been meaning to create a new geom for a data set that has been tidied in the following form: Katrina # A tibble: 3 x 9 storm_id date latitude longitude wind_speed ne se sw nw
Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41
4
votes
0 answers

Adding a polar background to a ggplot without using polar coordinates

I'd like make a plot using cartesian coordinate system, but then have it overlaid on a polar plot background, like that produced by coord_polar. Panel.background from theme.R only has element_rect; Ideally I could use something like…
Allen
  • 41
  • 2
4
votes
1 answer

What is the functionality of "non_missing_aes" in ggproto of ggplot2?

I'm writing extensions for ggplot2, and found that there's a newly added non_missing_aes parameter in ggproto that has not been explained in the official documentations of ggplot2 and official guide of extending ggplot2, could anyone tell me its…
passiflora
  • 332
  • 1
  • 9
4
votes
1 answer

ggproto: How to access non-aesthetic parameter values in compute_layer()?

I'm trying to make new geoms and stats. I tried a StatChull code from this vignette. My goal is to manipulate an external parameter which is not an aesthetic value. Something like this: stat_custom(data = df, mapping = aes(x = xval, y = val),…
Nirmal
  • 667
  • 5
  • 9
4
votes
1 answer

Add line segments to histogram in ggplot2 with radar coordinates

I am trying to make a polar histogram in ggplot2 with annotation lines which are not radial lines. The simple approach with coord_polar gives curved lines: library(ggplot2) d = data.frame(x=rep(seq(0, 350, 10), times=1:36)) lines = data.frame(x =…
Kent Johnson
  • 3,320
  • 1
  • 22
  • 23
4
votes
1 answer

Manipulate ggproto to get multiple layers

I'm trying to get multiple area layers out of a ggproto object. I don't know if this is even possible but in case it is, I'm unable to figure out how. For instance, how can I get the code below to produce two area layers where one has y coordinates…
TheComeOnMan
  • 12,535
  • 8
  • 39
  • 54
3
votes
1 answer

Default breaks in ggplot2 - where are the break limits dropped for legend guides and polar coordinate y axis labels

This is essentially a follow up question on How does ggplot calculate its default breaks? and I came across this when trying to find a slightly more elegant solution for How to add y-axis labels inside coord_polar graph ggplot?. Apparently, the…
tjebo
  • 21,977
  • 7
  • 58
  • 94
3
votes
1 answer

How does `geom_abline()` not affect the x and y scales?

Does anyone know which argument within geom_abline() is responsible for not affecting the x and y scales? The function draw_panel() w/i GeomAbline gets the underlying "ranges", but the line should than be typically lie outside the original…
moremo
  • 315
  • 2
  • 11
3
votes
1 answer

Extending ggplot with own geoms: Adapt default scale

Background After reading this beautiful answer on how to extend ggplot and the corresponding vignette I was trying to understand, how to extend ggplot. In a nutshell I understand, how the pieces are put together, but I am missing an important…
thothal
  • 16,690
  • 3
  • 36
  • 71
3
votes
1 answer

Call setup_data from parent class

Backround I was reading this excellent answer on how to place self adjusting text into bars: Resizeable text grobs inside bars After reading a bit on ggproto and especially the vignette on Extending ggplot I was wondering why the author had to…
thothal
  • 16,690
  • 3
  • 36
  • 71
3
votes
1 answer

Can you manually control ggplot2 geom_point dodging/overlapping order?

The recent update to ggplot2 (2.2.0) has broken some of our plots, as the order in which points are drawn has changed. For instance, the following code: library(dplyr) library(ggplot2) library(tibble) df <- tribble(~a, ~x, ~y, "I",…
3
votes
1 answer

Fill transparency with geom_violin

How can increase the alpha of the fill of violin plots but not the alpha of the boundary line? Changing alpha as an argument to geom_violin() results in both the fill and line changing.
saladi
  • 3,103
  • 6
  • 36
  • 61
2
votes
0 answers

Adapt `draw_key()` according to own `draw_panel()` for new `ggproto`

Based on the example in Master Software Development in R, I wrote a new geom_my_point(), adapting the alpha depending on the number of data points. This works fine, but the alpha value of the label is not correct if alpha is explicitly set. Here the…
moremo
  • 315
  • 2
  • 11
2
votes
0 answers

Error when trying to add a custom position adjustment to a package in ggplot2

I am trying to create position adjustments for ggplot2 that explicitly control the way points are spread out along the (x)-axis (rather than just adding a random jitter). I successfully used the examples position_jitter and position_jitterdodge to…
Melissa Key
  • 4,476
  • 12
  • 21