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
1
vote
1 answer

NA handling in **ggplot2** "Stat" in new ggproto

I'm trying to create a new Stat in a ggplot2 extension. I don't understand where NA values are removed, or how to write my new ggproto to accommodate other NA handling options. Where and how are NA's removed when creating a Stat, and how can this be…
Michael Roswell
  • 1,300
  • 12
  • 31
1
vote
1 answer

How to align scale transformation across geoms?

I have a geom_foo() which will do some transformation of the input data and I have a scale transformation. My problem is that these work not as I would expect together with other geom_*s in terms of scaling. To illustrate the behavior, consider…
markus
  • 25,843
  • 5
  • 39
  • 58
1
vote
2 answers

custom `geom_` with two different styles for plotting

My goal is to write a custom geom_ method that calculates and plots, e.g., confidence intervals and these should be plotted either as polygons or as lines. The question now is, where to check which "style" should be plotted? So far I have tried out…
moremo
  • 315
  • 2
  • 11
1
vote
1 answer

Can I access results of "setup_data" from "map_data"? (works fine for "compute_layout" but not "map_data") in ggplot2 ggproto

Can I access results of "setup_data" from "map_data" in ggpplot2 ggproto? (works fine for "compute_layout" but not "map_data") Hi folks. I'm working on a ggplot2 extension that will implement a new faceting method. I don't want to get into the nitty…
1
vote
2 answers

ggplot extension function to plot a superimposed mean in a scatterplot

I am trying to create a custom function that extends ggplot2. The goal of the function is to superimpose a mean with horizontal and vertical standard errors. The code below does the entire thing. library(plyr) library(tidyverse) summ <-…
Sam Min
  • 77
  • 5
1
vote
1 answer

How to change the color of geom_node in ggnetwork?

I am trying to do a disease simulation, where I want the infected node(is_infected>0) to be red and the un-infected(is_infected=0) node color to be cyan. results <- results %>% mutate( S = infected == 0, …
harperzhu
  • 49
  • 7
1
vote
1 answer

Using setup_params() in a ggplot2 geom

I'm working on making my own geom for ggplot2, and I've noticed that in ggplot2's documentation, it explicitly says that there is no setup_params() for geoms: Compared to Stat and Position, Geom is a little different because the execution of the…
Zeke
  • 617
  • 1
  • 6
  • 15
1
vote
0 answers

Column that is calculated inside `setup_data` not found by custom `GeomLink` function

I have a data.frame that looks like: type id x y label from to polarity group 1 link 3 560 -219 2 1 + 1 8 var 2 426 -276 hours worked per week NA NA 1 7 var 1…
symbolrush
  • 7,123
  • 1
  • 39
  • 67
1
vote
1 answer

Subset data in custom made `ggplot2` extension based on type

I'm working on a ggplot2 extension that works on data.frames looking a bit like: data <- data.frame( type = c("text", "text", "line", "line"), label = c("some label", "another one", NA, NA), x = c(0,10,2,4), y = c(0,10,3,7), xend = c(NA,…
symbolrush
  • 7,123
  • 1
  • 39
  • 67
1
vote
1 answer

Generating multiple geom_smooth lines of data samples

Attempting to build a new geom function here that will take a sample of points from a dataset by group, and fit a number of local regressions through the individual subsets. This would generate multiple local regression lines as samples of a full…
1
vote
1 answer

R plotROC package failing related to ggproto

Running install.packages("ggplot2", repos = "https://cloud.r-project.org") install.packages("plotROC", repos = "https://cloud.r-project.org") library(plotROC) plotROC::geom_roc() in R on my mac leads to > plotROC::geom_roc() Error: GeomRoc was…
zkurtz
  • 3,230
  • 7
  • 28
  • 64
1
vote
1 answer

ggplot not plotting ggmap object

When I run the code from the accepted answer (Plot coordinates on map), I get the following error message on the first run after installing ggmap: # loading the required packages library(ggplot2) library(ggmap) # creating a sample data.frame with…
Time Lord
  • 331
  • 2
  • 5
  • 12
1
vote
0 answers

How to call a new ggplot-based environment in R

Given the following ggplot-based environment (originally from: ggplot2: Multiple color scales or shift colors systematically on different layers?) GeomBoxplotDark <- ggproto(ggplot2:::GeomBoxplot,expr={ draw <- function(., data,…
Borja
  • 63
  • 2
  • 6
1
vote
2 answers

Why is bins parameter unknown for the stat_density2d function? (ggmap)

I have been stuck with this for hours. When I run this : library(ggmap) set.seed(1) n=100 df <- data.frame(x=rnorm(n, 0, 1), y=rnorm(n, 0, 1)) TestData <- ggplot (data = df) + stat_density2d(aes(x = x, y = y,fill = as.factor(..level..)),bins=4,…
hans glick
  • 2,431
  • 4
  • 25
  • 40
0
votes
0 answers

How to modify breaks and lables within ggproto?

I have a ggplot function (ggproto) to generate a manhattan plot. The code works, but I can't get my function to correctly position the breaks and labels on the x-axis. So I would really appreciate help on: How I can get my function to plot the axis…
Fabian_G
  • 431
  • 4
  • 16