Giter VIP home page Giter VIP logo

ggforce's Introduction

ggforce

R-CMD-check CRAN_Release_Badge CRAN_Download_Badge

Accelerating ggplot2

ggforce is a package aimed at providing missing functionality to ggplot2 through the extension system introduced with ggplot2 v2.0.0. Broadly speaking ggplot2 has been aimed primarily at explorative data visualization in order to investigate the data at hand, and less at providing utilities for composing custom plots a la D3.js. ggforce is mainly an attempt to address these “shortcomings” (design choices might be a better description). The goal is to provide a repository of geoms, stats, etc. that are as well documented and implemented as the official ones found in ggplot2.

Installation

You can install the released version of ggforce from CRAN with:

install.packages("ggforce")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("thomasp85/ggforce")

Features

ggforce is by design a collection of features with the only commonality being their tie to the ggplot2 API. Because of this an overview of all features would get too long for a README. The package has a website where every feature is described and justified with examples and plots. There should be a plot in the README of a visualization package though, so without further ado:

library(ggforce)
#> Loading required package: ggplot2
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() +
  facet_zoom(x = Species == "versicolor")

Code of Conduct

Please note that the ‘ggforce’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

ggforce's People

Contributors

andrewheiss avatar atusy avatar bart1 avatar benmarwick avatar clauswilke avatar crotoc avatar daniel-wells avatar dmurdoch avatar enchufa2 avatar evamaerey avatar ewenme avatar flrd avatar ilia-kats avatar imagejan avatar inventionate avatar jan-glx avatar jeff-mettel avatar jjchern avatar lepennec avatar michaelchirico avatar pursuitofdatascience avatar sidiropoulos avatar stragu avatar thomasp85 avatar ycl6 avatar yoda-vid avatar yutannihilation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ggforce's Issues

facet_zoom point labels

Is it possible to only shown point labels in the zoom-in panel (without showing point labels in the original panel)?

add median line to sina plot

Hi,

geom_sina() is a good alternative to geom_boxplot(), how can I add the median line to sina plot as boxplot does?

I know I can lay over boxplot over it
ggplot(df, aes(Distribution, Value)) + geom_violin(aes(fill = Distribution)) + geom_boxplot()

or add a summary, but only using a point:

stat_summary(fun.y=median, geom="point", fill= "white", shape = 21, size =2.5)
what if I just want a short median line ?

Thanks very much,
Tommy

release facet_wrap_paginate using dev version of ggplot2?

ggplot2 isn't released very often in the last few years, do you know if Hadley has plans of releasing it soon?

I was wondering why not releasing the paginate functions and simply specify the dev version of ggplot2 in the DESCRIPTION and travis. Of course it's a very selfish request :)

Connectograms

Hi,
I'm finally getting to look at ggforce as a basis for implementing connectograms, as you suggested back in july in response to a ggplot2 query.

The stat_pie structures actually look like they are very close to doing most of what I need to get started.

I'm still finding my way around the package code, so thought I'd make some queries before doing anything to stupid.

My first couple of changes were to look at options for changing direction (clockwise/counter clockwise) and orientation (vertical/horizontal). I can see that radial_trans has an offset option, but can't see
a way of setting it from a geom_arc_bar call. Also, is there a direction option hidden away? I had a quick go at adding such options but they interacted with "explode".

Finally, do you know of a way of checking what values (e.g. new dataframe columns) are computed internally by various stat_ without checking the code? I know you have some documentation but I was wondering about a ggplot way.

Finally, I think the only thing missing from the current code to implement connectograms is something giving the midpoint of the arcs. This is needed for links and labels. Looks like it should be easy enough to do, but thought I should check that it isn't already there somewhere.

Thanks

Working with geom_polygon and distribution charts

while creating choropleth maps and using geom_polygon to visualize spatial data, I have been looking for a way to use ggplot2 to draw a bar/pie chart at the centroids of each/selected polygons with stat = "identity"

library(dplyr)
library(ggplot2)
df <- data.frame(Region.ID = LETTERS[1:5],
                 Population.mill = sample(15:21, 5),
                 Male = sample(8:12, 5))
df <- df %>%
  mutate(Female = Population.mill - Male)
head(df)

For instance, in this data df, how would you add a pie/bar to show Male against Female for each/selected observation(s)? I know that I could play around with the base function plot() and a few other packages but my goal is to harness on the power and flexibility of ggplot2 to achieve the same.

Feature request: geom_bag

Following our Twitter exchange, I would love to have a geom_bag for a bivariate box plot. I previously mentioned this on ggalt, and made a start, but I'm not sure how to finish it. Also, I think there might be a better implementation in the code for this paper. What do you think?

alternative use of facet_zoom

facet_zoom() points at something important lacking in ggplot2: a tool to link across figure panels.

Would there be a way to use facet_zoom() in which the zoomed area could be populated with different plots altogether?

Concretely, this could be used when:

  • the data from the zoomed area (a subset of the data in the original panel) are used to produce a different visualisation, and we want to indicate the origin of the data;

  • all the data from the original panel are used in a different calculation, leading to a different visualisation in which the units cover a subset of the original units - for instance a linear fit is performed using all the data, but in the zoomed area we investigate the residuals in one area of the fit only.

Add units to ggplot

Using the units package we can associate (physical) units to quantities and guarantee that we only do arithmetic on compatible units. Plotting data with associated units, however, is cumbersome in ggplot. Can we make ggplot unit-aware?

geom_sf()

(Copied from here)

We need a geom_sf() to render simple feature objects in ggplots, e.g. where

nc = st_read(system.file("shape/nc.shp", package="sf"))
ggplot() + geom_sf(nc)

would add the polygon boundaries, and further argument can alter the color of polygons and polygon boundaries, as well as point and line geometries. I wrote some building blocks, basically functions that convert sf objects into grid grobs here and am willing to help out, but would appreciate some help getting started from someone who's been here before: @thomasp85, @hadley, @mdsumner , @hrbrmstr?

Issues to keep in mind:

  • can geom_sf control the aspect ratio used, such that 1 km north equals 1 km east?
  • when combining with ggmap(), I think web mercator is assumed: automatically use st_transform?
  • when combining different geom_sfs, can we verify that coordinate reference systems correspond?

stat_/geom_sina error with continuous x aesthetic

Occurs with both v0.1.0 and the master branch.

Minimal example:

library(ggplot2)

library(ggforce)

df <- data.frame(
    x = rep(1:10, each = 100),
    y = rnorm(10000)
)
ggplot(df, aes(x = factor(x), y = y)) + geom_sina()

Works.

ggplot(df, aes(x = x, y = y)) + geom_sina()

Produces the following error instead of complaining about a continuous x aesthetic: Error in f(...) : could not find function "has_groups".

ggforce.rdb missing

a minor glitch
devtools::install_github('thomasp85/ggforce') Downloading GitHub repo thomasp85/ggforce@master from URL https://api.github.com/repos/thomasp85/ggforce/zipball/master Fehler in eapply(ns_env(pkg), force, all.names = TRUE) : kann Datei '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/ggforce/R/ggforce.rdb' nicht öffnen: No such file or directory

facet_nest

Repeat plot but gradually subset data in a nested fashion

Improvements to facet_zoom

  • Let the user specify a scale range directly
  • Make it possible to have elements that only shows in the zoomed in panel

Area marker geoms

A range of geoms for marking an area containing points:

  • geom_mark_hull()
  • geom_mark_rect()
  • geom_mark_ellipsis()

Not really an issue :-)

ggalt has geom_xspline() which might fulfill the needs of your pending geom_spline()

Great package!

geom_sina with only one category

So I often use geom_violin or geom_boxplot to look at just one category. The standard way I do this is with something like the following

ggplot(df, aes(x=1, y=Var)) + geom_violin()

However, when trying to use geom_sina, I had to create a useless variable, because otherwise, I got the following error:
Error in f(...) : could not find function "has_groups"

The solution I've found, for now, is just the following:

df$Varx <- "Varx"
ggplot(df, aes(x=Varx, y=Var)) + geom_sina()

Thanks for the awesome package,
Gaius

geom_sina omits data when there's only one point

I'm having an issue with geom_sina (a package which I love, by the way) where if there is only one value that value is omitted. Here is a reproducible example:

simple <- data.frame(ID = c(rep(1,7)),
                     group = c("alpha", "beta", "alpha", "beta", "alpha", "beta", "alpha"),
                     version = c("on", "on", "off", "off", "on", "on", "off"),
                     value = c(1:4, 1:3))

ggplot() +   
    geom_point(data = simple, aes(x = ID, y = value, colour = ID),
               position = position_jitter(w = 0.2, h = 0)) +
    theme(legend.position = "none",
          axis.title.y = element_blank()) +
    facet_grid(version ~ group, shrink=FALSE)

ggplot() +   
    geom_sina(data = simple, aes(x = ID, y = value, colour = ID)) +
    theme(legend.position = "none",
          axis.title.y = element_blank()) +
    facet_grid(version ~ group, shrink=FALSE)

That creates two plots. The geom_point plot has all points, but the geom_sina one has omitted the single point in 'beta' x 'off' and gives the following warning:

Warning message:
Removed 1 rows containing missing values (geom_sina).

I suspect the removed row is the single point I wanted plotted. Is there a workaround or fix?

Thanks!

(Edited to fix sample data set)

facet_wrap_paginate

Nice work on ggforce and looking forward to the new release with ggplot2 2.2.0. In the meantime 2 questions on facet_wrap_paginate:

  • Is it possible to print all pages at once without using the for loop?
  • Is it possible to keep the requested layout e.g. ncol = 2, nrow = 2 on the last page even if there is in this case only 2 panels left to plot?

aes colour not respected by geom_sina like in geom_violin

When the data is split by colour, then geom_sina should split the data like geom_violin does, but the points stay in the same x position.

df <- data.frame(a=sample(LETTERS[1:6],1000,replace=TRUE), b=rnorm(1000),l=c(TRUE,FALSE))
ggplot(df, aes(x=a,y=b,colour=l)) + geom_violin() + geom_sina()

geom_sina has problems with artificial data

I tried to test some things and geom_violin copes with my stupid test data, but geom_sina throws errors. Maybe thats indicative of some problems - I don't really know.

df <- data.frame(g=c("A","B"),v=rep(c(rep(5,20),rep(10,20),rep(15,20)),2))
ggplot(df, aes(x=1,y=v)) + geom_violin()
ggplot(df, aes(x=1,y=v)) + geom_sina() //Error in f(...) : could not find function "has_groups"
ggplot(df, aes(x=g,y=v)) + geom_violin()
ggplot(df, aes(x=g,y=v)) + geom_sina() //Warning: Computation failed in `stat_sina()`: 'vec' must be sorted non-decreasingly and not contain NAs

using a vector in the raw scale to subset in facet_zoom

I was very happy to see your demo if facet_zoom() on twitter. I didn't have a real application to test it until yesterday. And I would like to zoom in based on a chosen on the response raw scale with a numerical vector.

Before I was using grid.arrange

gridExtra::grid.arrange(rr, rr + coord_cartesian(ylim = c(609, 611)) + theme(legend.position = "none"), nrow = 1, widths = c(0.65, 0.35))

image

Then, I tried facet_zoom using a naive approach
ggforce::facet_zoom(y = c(500, 680), shrink = FALSE, zoom.size = 0.75)

It looks roughly ok, but:

  • it introduced missing data, the naive approach does not create the appropriate logical vector to subset
  • the zoom is on the left, would prefer it on the right and exchange the legend
  • the chosen y-scale fits the dashed lines but are too zoomed in
    image

the final idea was to create the logical vector on the continuous response using dplyr::between

ggforce::facet_zoom(y = between(biomass, 609, 611), shrink = FALSE, zoom.size = 0.75)

but it is not like coord_cartesian to zoom in the plot, but select data.

the best I achieved was

image

the code is there:

library(tidyverse)
read_tsv("https://raw.githubusercontent.com/LSRU/r_workshop/gh-pages/data/competition.txt") %>%
  ggplot(aes(x = clipping, y = biomass)) + geom_boxplot() + labs(x = "Competition treatment", colour = NULL, y = "Biomass") +
  geom_hline(aes(colour = "mean r10", yintercept = 610.6667), linetype = "dashed") +
  geom_hline(aes(colour = "clipping3", yintercept = 610.6667 - 0.08333), linetype = "dashed") +
  geom_hline(aes(colour = "mean (r5, r10)", yintercept = (610.6667 + 610.5) / 2), alpha = 0.6) +
  geom_hline(aes(colour = "mean r5", yintercept = 610.5), linetype = "dashed") + # -> rr
  #ggforce::facet_zoom(y = c(500, 680), shrink = FALSE, zoom.size = 0.75)
  ggforce::facet_zoom(y = between(biomass, 600, 615), shrink = FALSE, zoom.size = 0.75)

Thanks again for all the very nice developments you did!

geom_sina issue

Thanks for this nice additions. I noticed a minor issue with the geom_sina function that wanted to bring to your attention. It's probably a scaling vs width issue.

I have several hundred datapoints in the range -2000 to 6000. When I plot my datapoints using geom_sina(size=1) without any additional options, I don't get any jitter (or if there is, the default width is too small to notice). Visually they all line up in a straight line.

When I re-scale my data to range -2 to 6 (divide by 1000), I get a nice jitter with appropriate width. The geom_violin function works fine with appropriate width without a need to re-scale my data, but geom_sina doesn't. It should be easy to replicate on your end, but I can send you my data values if you like.

geom_circle() + scale_*_reverse() inconsistent behaviour to rest of ggplot2

with geom_circle() adding scale_*_reverse() seems to do a multiply by -1 transformation and not a reverse the axis transformation as expected (i.e. what happens in other ggplot2 geoms)

library(ggforce)
#> Loading required package: ggplot2
d <- data.frame(x0 = 1, y0 = 1, r = 0.5)

ggplot(d) + geom_circle(aes(x0 = x0, y0 = y0, r = r))

ggplot(d) + geom_circle(aes(x0 = x0, y0 = y0, r = r)) + scale_y_reverse()

ggplot(d) + geom_circle(aes(x0 = x0, y0 = y0, r = r)) + scale_x_reverse()

devtools::session_info()
#> Session info --------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.3.2 (2016-10-31)
#>  system   x86_64, darwin16.1.0        
#>  ui       unknown                     
#>  language (EN)                        
#>  collate  en_CA.UTF-8                 
#>  tz       America/Vancouver           
#>  date     2016-12-06
#> Packages ------------------------------------------------------------------
#>  package    * version date       source        
#>  assertthat   0.1     2013-12-06 CRAN (R 3.3.2)
#>  backports    1.0.4   2016-10-24 CRAN (R 3.3.2)
#>  colorspace   1.3-1   2016-11-18 CRAN (R 3.3.2)
#>  DBI          0.5-1   2016-09-10 CRAN (R 3.3.2)
#>  devtools     1.12.0  2016-06-24 CRAN (R 3.3.2)
#>  digest       0.6.10  2016-08-02 CRAN (R 3.3.2)
#>  dplyr        0.5.0   2016-06-24 CRAN (R 3.3.2)
#>  evaluate     0.10    2016-10-11 CRAN (R 3.3.2)
#>  formatR      1.4     2016-05-09 CRAN (R 3.3.2)
#>  ggforce    * 0.1.1   2016-11-28 CRAN (R 3.3.2)
#>  ggplot2    * 2.2.0   2016-11-11 CRAN (R 3.3.2)
#>  gtable       0.2.0   2016-02-26 CRAN (R 3.3.2)
#>  htmltools    0.3.5   2016-03-21 CRAN (R 3.3.2)
#>  knitr        1.15.1  2016-11-22 CRAN (R 3.3.2)
#>  labeling     0.3     2014-08-23 CRAN (R 3.3.2)
#>  lazyeval     0.2.0   2016-06-12 CRAN (R 3.3.2)
#>  magrittr     1.5     2014-11-22 CRAN (R 3.3.2)
#>  MASS         7.3-45  2016-04-21 CRAN (R 3.3.2)
#>  memoise      1.0.0   2016-01-29 CRAN (R 3.3.2)
#>  munsell      0.4.3   2016-02-13 CRAN (R 3.3.2)
#>  plyr         1.8.4   2016-06-08 CRAN (R 3.3.2)
#>  R6           2.2.0   2016-10-05 CRAN (R 3.3.2)
#>  Rcpp         0.12.8  2016-11-17 CRAN (R 3.3.2)
#>  rmarkdown    1.2     2016-11-21 CRAN (R 3.3.2)
#>  rprojroot    1.1     2016-10-29 CRAN (R 3.3.2)
#>  scales       0.4.1   2016-11-09 CRAN (R 3.3.2)
#>  stringi      1.1.2   2016-10-01 CRAN (R 3.3.2)
#>  stringr      1.1.0   2016-08-19 CRAN (R 3.3.2)
#>  tibble       1.2     2016-08-26 CRAN (R 3.3.2)
#>  tweenr       0.1.5   2016-10-10 CRAN (R 3.3.2)
#>  udunits2     0.13    2016-11-17 CRAN (R 3.3.2)
#>  units        0.4     2016-11-21 CRAN (R 3.3.2)
#>  withr        1.0.2   2016-06-20 CRAN (R 3.3.2)

facet_zoom shading region

The shading on the full data panel which indicates the axis range on the zoom panel doesn't fully cover the axis range actually used in the zoom panel.

df <- data.frame(weight = c(1.2, 2.5, 3.6, 4.0, 4.5), outcome = c(20, 2100, 200, 10, 2500))

ggplot(df, aes(weight, outcome)) +
  geom_point() +
  facet_zoom(y = outcome < 300)

facet_zoom with different data and different plot

Is it possible to have zoomed region to have different Y values and different type of plot?

Example:

library(ggplot2)
library(ggforce)

#dummy data
set.seed(1)
df1 <- data.frame(x = 1:100, y = runif(100), zoom = c(rep("a", 30), rep("b", 20), rep("c", 50)))
df2 <- data.frame(x = 1:100, y = runif(100, 1, 10))

ggplot(df1, aes(x, y)) +
  geom_point() + 
  facet_zoom(x = zoom == "b")

plot1

All great but this is not what I want. I need to have the zoomed region to have plot based on different data as Y value, and different plot type:

gg1 <- ggplot(df1, aes(x, y)) + geom_point()
gg2 <- ggplot(df2, aes(x, y)) + geom_line()

#interseting area zoomed in with line plot
range(df1[ df1$zoom == "b", "x"])
# [1] 31 50
gg2zoom <- ggplot(df2[ df2$x >= 31 & df2$x <= 50, ], aes(x, y)) + 
  geom_line()

#merge plot vertically
cowplot::plot_grid(gg1, gg2zoom, nrow = 2)

plot2

I would want above plot with your type of shading to show zooming area, here is expected output with bit of Paintburshing:

plot3

Possible? Maybe other workarounds?

using facet_zoom with coord_quickmap

Is there a nice way to combine facet_zoom with coord_quickmap? I'd like to have a combination of the first plot with a zoom in around the UK. When I try to use facet_zoom, I can either forgo the call to coord_quickmap and get the correct zoom, but a weird aspect ratio (ex 2) or I can include coord_quickmap but then while the zoom facet has the right aspect ratio, it shows the whole map (ex 3)

library(ggforce)
#> Loading required package: ggplot2
library(maps)

global_map <- map_data("world")

point_data <- data.frame(lng = c(runif(50, -10, -3), runif(50, -50, -3)), lat = c(runif(50, 
  54, 60), runif(50, 54, 65)))

p <- ggplot() + geom_polygon(aes(x = long, y = lat, group = group), fill = "#4FFFB0", 
  colour = NA, data = global_map) + theme(panel.grid = element_blank(), panel.background = element_rect(fill = "#0087BD")) + 
  geom_point(aes(x = lng, y = lat, colour = pct_change), colour = "yellow", 
    data = point_data)

p + coord_quickmap(xlim = c(-52.25, -5), ylim = c(54.5, 64.5))

p + facet_zoom(xlim = c(-10, -3), ylim = c(54, 60), horizontal = FALSE)

p + facet_zoom(xlim = c(-10, -3), ylim = c(54, 60), horizontal = FALSE) + coord_quickmap(xlim = c(-52.25, 
  -5), ylim = c(54.5, 64.5))

facet_zoom

x and y should all be provided

If only provide x or y, it fails even with the example you posted in twitter.

> p + facet_zoom(x = Species != 'setosa', y = Species == 'versicolor')
> p + facet_zoom(y = Species == 'versicolor')
Error in x_scales[[2]] : subscript out of bounds

fail if it was wrapped in a function

require(ggtree)
tr <- rtree(50)
p <- ggplot(tr, aes(x, y)) + geom_tree2() + geom_label(aes(label=node))

tree_zoom <- function(treeview, node, ...) {    
    treeview + facet_zoom(xy = node %in% get.offspring.df(treeview$data, node), ...)
}

tree_zoom(ggplot(tr, aes(x, y)) + geom_tree2() + geom_label(aes(label=node)), node=84)

screen shot 2016-09-30 at 10 40 43 am

ugly when not using theme_grey

p1 <- ggplot(tr, aes(x, y)) + geom_tree2() + geom_label(aes(label=node))+ theme_tree()
p1 <- p1 + facet_zoom(xy = node %in% get.offspring.df(p1$data, 84))

multiplot(p1, p1+theme_grey(), ncol=2)

screen shot 2016-09-30 at 10 39 23 am

'facet_zoom(xy =' gives wrong axis values

The following example in the vignette has the wrong y-axis values in the zoom plot

ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
    geom_point() +
    facet_zoom(xy = Species == "versicolor")

facet_zoom with mapping

Similar but different to #56. With geom_sf() on its way to ggplot2 it would be great to have projection-aware facet_zooming. Part of this would likely require that the original and zoomed panels not necessarily be the same height/width, in order to maintain projections. For example, it would be great to be able to zoom a region of a map

library(dplyr)
library(maps)
library(ggplot2) 
library(ggforce) 
aus_map <- map_data("world") %>% 
  filter(region == "Australia", 
         is.na(subregion) | subregion %in% c("Tasmania", "Kangaroo Island"))
p <- ggplot() + 
  geom_polygon(aes(x = long, y = lat, group = group), 
               colour = NA, 
               data = aus_map) 
p + facet_zoom(xlim = c(131, 148), ylim = c(-45, -32), 
               zoom.size = 4)

Attempting to do similar with the sf branch of ggplot2 just produces the unzoomed map in both panels and seems to miss the zoom highlight, though it certainly looks neater.

library(sf)      
library(maps)
library(ggplot2) # devtools::install_github("tidyverse/ggplot2@sf") ## NOTE sf branch
library(ggforce)
world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE))
ggplot() + 
  geom_sf(data = world1) + 
  coord_sf(xlim = c(110, 160), ylim = c(-45, -10)) + 
  facet_zoom(xlim = c(132, 148), ylim = c(-45, -32))

This has potential to look really awesome if the unzoomed panel could have its height adjusted to maintain projection (width can currently be somewhat manually adjusted via zoom.size) and if the subsetting was compatible with the sf features (appropriate highlight/zoom).

I know it's a dev feature, so this is just 'down the track' thinking.

facet_wrap_paginate scales error

ggplot(diamonds) +
  geom_point(aes(carat, price), alpha = 0.1) +
  facet_wrap_paginate(~cut:clarity, scales = 'free', ncol=3, nrow=3, page =3)
ggplot(diamonds) +
  geom_point(aes(carat, price), alpha = 0.1) +
  facet_wrap_paginate(~cut:clarity, scales = 'free_y', ncol=3, nrow=3, page =3)
ggplot(diamonds) +
  geom_point(aes(carat, price), alpha = 0.1) +
  facet_wrap_paginate(~cut:clarity, scales = 'free_x', ncol=3, nrow=3, page =3)

All codes return an error: Error in FUN(X[[i]], ...) : Unknown input

ggplot(diamonds) +
  geom_point(aes(carat, price), alpha = 0.1) +
  facet_wrap_paginate(~cut:clarity, scales = 'fixed', ncol=3, nrow=3, page =3)

Works as intended.

Facet_zoom + geom_abline issue

How to add abline to facet_zoom plot if I want to see it both on original and zoomed parts?
Currently I get this error:

ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
    geom_point() + facet_zoom(x = Species == "versicolor") +
    geom_abline(slope =0.3) 

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 0, 1

facet_wrap_paginate - not producing faceted plot on final page

In producing faceted plots over multiple pages, where the final page is not entirely filled with plots, the faceting style is not always carried over. For instance, if there are 3 plots per page and final page has only a single faceted plot, instead of occupying 1/3 of the page - it takes up the whole page. Reproduced with the following code:

`# Calculate the number of pages with 3 panels per page
n_pages <- ceiling(length(levels(diamonds$cut)) * length(levels(diamonds$clarity)) / 3)'

'# Draw each page
for (i in seq_len(n_pages)) {
print(ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 1, scales = "fixed", page = i))
}`

It goes from page 13 - in the above case:
pg13

to page 14 - the last page:

pg14

When the number of plots per page are changed - we end up with another a strange arrangement of grobs (2x3 vs 3x3):

grob2x3

Using the following code:
`# Calculate the number of pages with 9 panels per page
n_pages <- ceiling(
length(levels(diamonds$cut)) * length(levels(diamonds$clarity)) / 9)'

'# Draw each page
for (i in seq_len(n_pages)) {
print(ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 3, scales = "fixed", page = i))
}`

scale="free" on facet_wrap_paginate throws error

I noticed this whilst working with my own data. I've reproduced using the diamond df below: When scales is changed from its default ("fixed") - to (say) "free", you get the error -

Error in FUN(X[[i]], ...) : Unknown input

# Calculate the number of pages with 9 panels per page n_pages <- ceiling( length(levels(diamonds$cut)) * length(levels(diamonds$clarity)) / 9)

# Draw each page for (i in seq_len(n_pages)) { print(ggplot(diamonds) + geom_point(aes(carat, price), alpha = 0.1) + facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 3, scales = "free", page = i))

Traceback:
19 stop("Unknown input") 18 FUN(X[[i]], ...) 17 lapply(grobs, height_cm) 16 unlist(lapply(grobs, height_cm)) 15 unit(max(unlist(lapply(grobs, height_cm))), "cm") 14 FUN(newX[, i], ...) 13 apply(axis_mat_x_top, 1, max_height) 12 unit(apply(axis_mat_x_top, 1, max_height), "cm") 11 f(...) 10 FacetWrap$draw_panels(panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) 9 f(...) 8 self$draw_panels(panels, layout, x_scales, y_scales, ranges, coord, data, theme, self$params) 7 f(..., self = self) 6 self$facet$render_panels(panels, self$panel_layout, self$panel_scales$x, self$panel_scales$y, self$panel_ranges, coord, data, theme, labels) 5 f(..., self = self) 4 layout$render(geom_grobs, data, plot$coordinates, theme, plot$labels) 3 ggplot_gtable(data) 2 print.ggplot(ggplot(diamonds) + geom_point(aes(carat, price), alpha = 0.1) + facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 3, scales = "free", page = i)) 1 print(ggplot(diamonds) + geom_point(aes(carat, price), alpha = 0.1) + facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 3, scales = "free", page = i))

Examples please

Example plots and code in README will do wonders to motivate me to install and use this. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.