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:

75 questions
58
votes
8 answers

qqnorm and qqline in ggplot2

Say have a linear model LM that I want a qq plot of the residuals. Normally I would use the R base graphics: qqnorm(residuals(LM), ylab="Residuals") qqline(residuals(LM)) I can figure out how to get the qqnorm part of the plot, but I can't seem to…
Peter
  • 4,041
  • 4
  • 25
  • 38
53
votes
4 answers

ggmap Error: GeomRasterAnn was built with an incompatible version of ggproto

I'm using ggmap, and got the error below: Error: GeomRasterAnn was built with an incompatible version of ggproto. Please reinstall the package that provides this extension. I've installed the latest version of both ggmap(2.6.1) and ggplot2(2.2.0),…
dingding
  • 531
  • 1
  • 4
  • 4
53
votes
2 answers

Split violin plot with ggplot2

I'd like to create a split violin density plot using ggplot, like the fourth example on this page of the seaborn documentation. Here is some data: set.seed(20160229) my_data = data.frame( y=c(rnorm(1000), rnorm(1000, 0.5), rnorm(1000, 1),…
user102162
  • 695
  • 1
  • 7
  • 9
46
votes
3 answers

How to use an image as a point in ggplot?

Is there some way to use a specific small image as a point in a scatterplot with ggplot2. Ideally I will want to resize the images based on an variable. Here's an example: library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(aes(size =…
griffin
  • 2,938
  • 8
  • 34
  • 34
32
votes
3 answers

Changing whisker definition in geom_boxplot

I'm trying to use ggplot2 / geom_boxplot to produce a boxplot where the whiskers are defined as the 5 and 95th percentile instead of 0.25 - 1.5 IQR / 0.75 + IQR and outliers from those new whiskers are plotted as usual. I can see that the…
cswingle
  • 555
  • 1
  • 8
  • 13
25
votes
4 answers

How to adjust facet size manually

I have a faceted plot with very diverse data. So some facets have only 1 x value, but some others have 13 x values. I know there is the parameter space='free' which adjusts the width of each facet by the data it represents. My question, is there a…
drmariod
  • 9,470
  • 8
  • 48
  • 96
24
votes
2 answers

Display custom image as geom_point

Is it possible to display custom image (say png format) as geom_point in R ggplot? library(png) pic1 <- readPNG("pic1.png") png("Heatmap.png", units="px", width=3200, height=3200, res=300) ggplot(data_frame, aes(medium, day, fill = Transactions)) …
Seth
  • 259
  • 1
  • 2
  • 6
20
votes
2 answers

ggplot2: geom_text resize with the plot and force/fit text within geom_bar

This is actually two questions in one (not sure if goes against SO rules, but anyway). First question is how can I force a geom_text to fit within a geom_bar? (dynamically according to the values plotted) Looking around, the solutions I found were…
elikesprogramming
  • 2,107
  • 1
  • 12
  • 33
19
votes
1 answer

Warning when defining factor: duplicated levels in factors are deprecated

I am having a little trouble with my radar chart in R. Even though the plot is fine I am getting the following warning: > source('~/.active-rstudio-document') Warning message: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else…
Stücke
  • 493
  • 3
  • 6
  • 24
18
votes
3 answers

ggplot2: Adding sample size information to x-axis tick labels

This question is related to Create custom geom to compute summary statistics and display them *outside* the plotting region (NOTE: All functions have been simplified; no error checks for correct objects types, NAs, etc.) In base R, it is quite…
Steve M
  • 341
  • 1
  • 2
  • 6
18
votes
7 answers

Hollow histogram or binning for geom_step

I would like to draw a hollow histogram that has no vertical bars drawn inside of it, but just an outline. I couldn't find any way to do it with geom_histogram. The geom_step+stat_bin combination seemed like it could do the job. However, the bins of…
14
votes
2 answers

Fill arrow on geom_curve ggplot2

Is there a way to get the arrowhead closed on geom_curve? The same code works with geom_segment. Maybe its a bug? library(tidyverse) set.seed(123) data <- data_frame(x = rnorm(10), y = rnorm(10)) # NO ARROWHEAD FILL ggplot(data, aes(x, y)) + …
glaucon
  • 208
  • 2
  • 9
12
votes
2 answers

Creating a multiple column facet function

I am trying to create a facet_multi_col() function, similar to the facet_col() function in ggforce - that allows for a facet layout with a space argument (which is not available in facet_wrap()) - but over multiple columns. As in the last plot below…
guyabel
  • 6,849
  • 5
  • 42
  • 76
11
votes
3 answers

ggplot2::coord_cartesian on facets

coord_cartesian doesn't allow one to set per-facet coordinates, and using other range-limiting tends to produce a straight-line on the specific extreme. Since we have widelay-varying y-ranges, we can't set the limits on all facets identically;…
r2evans
  • 77,184
  • 4
  • 55
  • 96
11
votes
1 answer

How to make a custom ggplot2 geom with multiple geometries

I've been reading the vignette on extending ggplot2, but I'm a bit stuck on how I can make a single geom that can add multiple geometries to the plot. Multiple geometries already exist in ggplot2 geoms, for example, we have things like geom_contour…
Ben
  • 38,669
  • 17
  • 120
  • 206
1
2 3 4 5