Git Product home page Git Product logo

ggplot2's Introduction

tidyverse

CRAN status R-CMD-check Codecov test coverage

Overview

The tidyverse is a set of packages that work in harmony because they share common data representations and API design. The tidyverse package is designed to make it easy to install and load core packages from the tidyverse in a single command.

If you’d like to learn how to use the tidyverse effectively, the best place to start is R for Data Science (2e).

Installation

# Install from CRAN
install.packages("tidyverse")
# Install the development version from GitHub
# install.packages("pak")
pak::pak("tidyverse/tidyverse")

If you’re compiling from source, you can run pak::pkg_system_requirements("tidyverse"), to see the complete set of system packages needed on your machine.

Usage

library(tidyverse) will load the core tidyverse packages:

You also get a condensed summary of conflicts with other packages you have loaded:

library(tidyverse)
#> ── Attaching core tidyverse packages ─────────────────── tidyverse 2.0.0.9000 ──
#> ✔ dplyr     1.1.3     ✔ readr     2.1.4
#> ✔ forcats   1.0.0     ✔ stringr   1.5.0
#> ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
#> ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
#> ✔ purrr     1.0.2     
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

You can see conflicts created later with tidyverse_conflicts():

library(MASS)
#> 
#> Attaching package: 'MASS'
#> The following object is masked from 'package:dplyr':
#> 
#>     select
tidyverse_conflicts()
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
#> ✖ MASS::select()  masks dplyr::select()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

And you can check that all tidyverse packages are up-to-date with tidyverse_update():

tidyverse_update()
#> The following packages are out of date:
#>  * broom (0.4.0 -> 0.4.1)
#>  * DBI   (0.4.1 -> 0.5)
#>  * Rcpp  (0.12.6 -> 0.12.7)
#>  
#> Start a clean R session then run:
#> install.packages(c("broom", "DBI", "Rcpp"))

Packages

As well as the core tidyverse, installing this package also installs a selection of other packages that you’re likely to use frequently, but probably not in every analysis. This includes packages for:

  • Working with specific types of vectors:

    • hms, for times.
  • Importing other types of data:

    • feather, for sharing with Python and other languages.
    • haven, for SPSS, SAS and Stata files.
    • httr, for web apis.
    • jsonlite for JSON.
    • readxl, for .xls and .xlsx files.
    • rvest, for web scraping.
    • xml2, for XML.
  • Modelling

    • modelr, for modelling within a pipeline
    • broom, for turning models into tidy data

Code of Conduct

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

ggplot2's People

Contributors

batpigandme avatar briandiggs avatar clauswilke avatar cpsievert avatar dkahle avatar dpseidel avatar eliocamp avatar hadley avatar has2k1 avatar hrbrmstr avatar jakeruss avatar jiho avatar jimhester avatar jofrhwld avatar jorane avatar jrnold avatar karawoo avatar kohske avatar krlmlr avatar lionel- avatar michaelchirico avatar mine-cetinkaya-rundel avatar olivroy avatar paleolimbot avatar tdhock avatar teunbrand avatar thomasp85 avatar topepo avatar wch 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  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

ggplot2's Issues

hcl colour scale

That takes hue, chroma and luminance as inputs and outputs colour.

facet_grid free space calculations incorrect

da <- data.frame(
  x = rep(1:5, 2),
  y = c(1+(0:4), 1+(0:4)/10),
  z = rep(1:2, each=5))

qplot(x, y, data=da, group=z, geom="line") +
  facet_grid(z ~ ., scales="free_y", space="free")

Panel two is about half the size it should be

geom_abline doesn't work with scale_log10

myd <- data.frame(
  myvar = c(1,5,10,50,100,500,1000,5000,10000),
  myvarb = c(1:9)
)

base <- ggplot(myd, aes(myvarb, myvar))+
  geom_point()+
  geom_abline(intercept = 1, slope = 100)

base + scale_y_log10()

stat_ecdf

Create stat for computing ecdf. Work with geom_step to create plot of ecdf.

coord_map and geom_tile

library(maps)
data <- data.frame(
  lat = c(-41,-42,-41,-42),
  lon = c(170,170,171,171),
  var = c(1,2,3,4))
coast <- data.frame(map("nz", plot=FALSE)[c("x","y")])

plot <- ggplot(data,aes(lon, lat)) + 
  geom_tile(aes(fill = var)) +
  geom_polygon(data = coast,aes(x, y))
plot #OK
plot + coord_equal() #OK
plot + coord_map()

Legend with three constraints doesn't work

data <- data.frame(x = 1:10, y1 = 1:10, y2 = 1:10)
ggplot(data=data, aes(x=x)) + geom_smooth(aes(y=y1, linetype="y1"))
ggplot(data=data, aes(x=x)) + geom_smooth(aes(y=y1, color="y1"))
ggplot(data=data, aes(x=x)) + geom_smooth(aes(y=y1, color="a", linetype="b"))

Legend size calculated incorrectly

dummy <- data.frame(
       x = rnorm(1000),
       y = rnorm(1000),
       z = gl(2, 500, labels = c("A rather long label", "An even longer
label than the first label"))
)
ggplot(dummy, aes(x = x, y = y, colour = z)) + geom_point()
last_plot() + theme_gray(base_size = 4)

Reported by Thierry Onkelinx

Faster stat_smooth

Exercise 11 of chapter 4 of Simon Woods' GAM book - having obtained the model matrix and penalty for the smooth from the object returned by e.g. smooth.construct2(s(x,bs="cr"),data=list(x=x),knots=NULL)

Should be faster for the special case needed for stat_smooth.

Transformations of scale_colour_gradient don't work

The following two plots are identical:

qplot(carat, price, data = diamonds, geom = "bin2d") +
  scale_colour_gradient()

qplot(carat, price, data = diamonds, geom = "bin2d") +
  scale_colour_gradient(trans = "log10")

coord_polar incorrectly combines expression tick marks

df <- data.frame(x = runif(10) * 2 * pi)

base <- ggplot(df, aes(x, 1)) + 
  geom_point() + 
  ylim(0,1.1) + 
  coord_polar()

breaks <- seq(0, 2 * pi, pi/2)
base + scale_x_continuous(limits = range(breaks), breaks = breaks)

labels <- c("0", expression(frac(pi,2)), expression(pi),
   expression(frac(3*pi,2)), expression(pi))
base + scale_x_continuous(limits = range(breaks), 
  breaks = breaks, labels = labels)
#0 point converted to string

geom_contour

geom_contour generates errors and does not correctly draw contours for density_2d

qplot(rating, length, data = movies, geom = "density2d",
  colour = factor(Comedy), ylim = c(0, 150))

Dates not correctly transformed when used as colour scale

a <- structure(list(date = structure(c(1227633710, 1227633725, 1227633740, 
1227633756, 1227633771, 1227633786, 1227633802, 1227633818, 1227633833, 
1227633848, 1227633863, 1227633878), class = c("POSIXt", "POSIXct"
), tzone = ""), x = c(10.2516422, 11.1053127, 11.6594761, 13.2709195, 
14.0127093, 14.7598268, 14.6802017, 15.2590637, 15.5089719, 15.5101305, 
15.1716798, 14.9050077), y = c(-11.5090033, -10.8087639, -10.0120475, 
-7.9856268, -6.5551218, -5.1593914, -4.1750486, -2.3780065, -0.5245896, 
1.3263083, 3.3031301, 4.5791333)), .Names = c("date", "x", "y"
), row.names = c(NA, -12L), class = "data.frame")

ggplot(a) + geom_point(aes(x=x, y=y, colour=date))

coord_flip and geom_hline/geom_vline

qplot(mpg, wt, data = mtcars) + geom_vline(xintercept = 20) + coord_flip()
qplot(mpg, wt, data = mtcars) + geom_hline(yintercept = 5) + coord_flip()

Order aesthetic does not affect order of dodged groups

In the following example, the groups should be displayed in alphabetical order: gain on the left and loss on the right.

df <- data.frame( 
  FRAME = factor(c("Loss", "Gain", "Loss", "Gain")), 
  Mean = c(5.28, 5.23, 4.95, 5.12), 
  FOCUS = factor(c("Prevention", "Prevention", "Promotion", "Promotion"))
)

dodge <- position_dodge(width=0.90)
ggplot(df, aes(FOCUS, Mean, order=FRAME, colour=FRAME)) + 
  geom_point(position=dodge, size = 4)

Store labels in options

By default, scale names should be stored in options. This will allow simplification of the current default scale production so that scales only need to be added when the plot is drawn, and fix the following bugs:

  • can not use ylab() to set the label for histograms
  • annotate overrides the scale defaults

Ordinal scales

For integers with limited range and ordered factors, ggplot2 should use ordinal scales. In particular, colour should default to an sequential brewer palette, and shape should use shapes with increasing number of edges.

Better interaction with theme font size and pointsize

I'm not sure what to do here, but it should at least be documented.

p = qplot(runif(5),runif(5)) + opts(title="A dumb plot")

# this is the default
theme_set(theme_grey(12))
quartz(width=5, height=4, pointsize=12)
p

# this has display issues (overwriting in legends etc.) because the
# font size is too large compared to what the device "expects"
theme_set(theme_grey(25))
quartz(width=5, height=4, pointsize=8)
p

# when the pointsize is set accordingly, the proportions are
# "harmonious" again (well, it still does not look great that's because
#25 is much to big for this size of plot)
theme_set(theme_grey(25))
quartz(width=5, height=4, pointsize=25)
p

# Ahhh, that's better
theme_set(theme_grey(10))
quartz(width=5, height=4, pointsize=10)
p

For data, NULL != data.frame()

For example,

qplot(mpg, wt, data = mtcars) + 
  geom_point(data = data.frame(), colour = "red")

should display black points.

This can occur when subsetting and is annoying.

Layer with all coordinates set does not work

ggplot(mtcars, aes(mpg, wt)) + 
  geom_point() + 
  geom_rect(xmin = 15, xmax = 20, ymin = 3, ymax = 5)

vs.

ggplot() + 
  geom_point(aes(mpg, wt), data = mtcars) + 
  geom_rect(xmin = 15, xmax = 20, ymin = 3, ymax = 5)

scales should generate compatible legend keys

set.seed(1)
d = data.frame(x=1:10, y=runif(10), z=runif(10))
ggplot(d) + geom_point(aes(x,y, size=z, colour=z)) + scale_area()
# fails

set.seed(7)
d = data.frame(x=1:10, y=runif(10), z=runif(10))
ggplot(d) + geom_point(aes(x,y, size=z, colour=z)) + scale_area()
# works

Ordering across geoms is inconsistent

df <- data.frame( 
  FRAME = factor(c("Loss", "Gain", "Loss", "Gain")), 
  Mean = c(5.28, 5.23, 4.95, 5.12), 
  FOCUS = factor(c("Prevention", "Prevention", "Promotion", "Promotion"))
)

dodge <- position_dodge(width=0.90)
base <- ggplot(df, aes(FOCUS, Mean, fill=FRAME, colour=FRAME)) + 
  geom_point(position=dodge, size = 4)

# Do work:
base + geom_text(aes(label = Mean), position = dodge)
base + geom_bar(position=dodge, stat="identity")
# Don't work
base + geom_bar(position=dodge)
base + geom_boxplot(position=dodge)

legend should respect layer data subset

In this example, points and lines are used for both values.

df.actual <- data.frame(x = 1:10, y = 1:10)
df.approx <- data.frame(x = 1:15, y = 1:15 + rnorm(15, sd = 3))
ggplot(df.actual, aes(x, y)) +
  geom_point(aes(colour="Actual")) +
  geom_line(aes(colour="Approximate"), data=df.approx)

geom_rect and geom_line should support infinite coordinates

This would be useful for annotations, and for geom_vline and geom_hline. The main complication would be ensuring correct translation in coordinate systems.

  ggplot(data.frame(x=0:1,y=0:1)) +
    geom_rect(aes(x=x,y=y),xmin=.1,xmax=.2,ymin=-Inf,ymax=Inf)

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.