Questions tagged [ggplot2]

ggplot2 is an actively maintained open-source chart-drawing package for R, written by Hadley Wickham, based upon the principles of "Grammar of Graphics". It partially replaces R's basic plot and the lattice package, while providing a clean, powerful, orthogonal and fun API.

ggplot2 is a package for R, written by Hadley Wickham, based upon the principles of Grammar of Graphics by Leland Wilkinson. It partially replaces R's graphics and the lattice packages, while providing a clean, powerful and fun API.

Repositories

Vignettes

Frequently Asked Questions

Books

Other resources

R packages extending ggplot2:

  • cowplot. This provides support for arranging multiple ggplot plots using a robust grid system, as well as tools for annotating plots, and a theme optimized for academic publications.
  • GGally. Contains templates for different plots to be combined into a plot matrix, as well as a parallel coordinate plot function.
  • ggalt. Extra Coordinate Systems, Geoms, Statistical Transformations, Scales & Fonts for ‘ggplot2’.
  • ggcolpairs Combination of GGplot2 plots into a matrix based on data columns
  • ggdendro Tools for extracting dendrogram and tree diagram plot data for use with ggplot
  • granovaGG Graphical Analysis of Variance Using ggplot2
  • nvis Combination of visualization functions for nuclear data using ggplot2 and ggcolpairs
  • ggmap. Allows visualization of spatial data and models on top of Google Maps, OpenStreetMap, or Stamen Maps using ggplot2
  • ggsignif. Provides a single layer geom_signif which can calculate the significance of a difference between groups and add the annotation to the plot
  • ggstance. Provides horizontal versions of ggplot2's stats and geoms.
  • ggtern. An extension to ggplot2 for the creation of ternary diagrams
  • ggthemes. Contains extra geoms, scales, and themes for use with ggplot2
  • ggsubplot. Makes it easy to embed customized subplots within larger graphics
  • gridExtra. This is useful for arranging multiple ggplot objects together, as ggplot2 is based upon the grid graphics system. An alternative to cowplot.
  • ggpmisc. Makes it easy to add equations and parameters from model fits as text or labels, to label peaks and/or valleys, to use time series objects as data, to label or highlight observations in low density regions, to debug stats code.
  • ggrepel. Makes it easy to add repulsive text and labels (relocated to avoid overlap).
  • ggspectra. Makes it easy to plot and annotate light spectra.
  • ggridges. Partially overlapping line plots that create the impression of a mountain range, useful for visualizing changes in distributions over time or space.
  • ggtext. Improved text rendering support for ggplot2, enables complex formatted plot labels.

See also the ggplot2 extensions web site.

Related tags

54496 questions
122
votes
2 answers

How to put labels over geom_bar for each bar in R with ggplot2

I've found this, How to put labels over geom_bar in R with ggplot2, but it just put labels(numbers) over only one bar. Here is, let's say, two bars for each x-axis, how to do the same thing? My data and code look like this: dat <- read.table(text…
Puriney
  • 2,417
  • 3
  • 20
  • 25
120
votes
2 answers

Change the position of the strip label in ggplot from the top to the bottom?

I know this is not quite a data visualization issue, but the boss asked for it, so I need to figure out if it is possible.
lokheart
  • 23,743
  • 39
  • 98
  • 169
119
votes
3 answers

group by two columns in ggplot2

Is it possible to group by two columns? So the cross product is drawn by geom_point() and geom_smooth()? As example: frame <- data.frame( series <- rep(c('a', 'b'), 6), sample <- rep(c('glass','water', 'metal'), 4), data <-…
Reactormonk
  • 21,472
  • 14
  • 74
  • 123
119
votes
1 answer

How to left align text in annotate from ggplot2

My example is: qplot(mtcars$mpg) + annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text") How do I get the text here to be left aligned? So that the 'Some's line up with each other.
kennyB
  • 1,963
  • 3
  • 17
  • 22
118
votes
4 answers

Remove facet_wrap labels completely

I'd like to remove the labels for the facets completely to create a sort of sparkline effect, as for the audience the labels are irrelevant, the best I can come up with is: library(MASS) library(ggplot2) qplot(week,y,data=bacteria,group=ID,…
Sean
  • 3,765
  • 3
  • 26
  • 48
117
votes
8 answers

How to add texture to fill colors in ggplot2

I'm currently using scale_brewer() for fill and these look beautiful in color (on screen and via color printer) but print relatively uniformly as greys when using a black and white printer. I searched the online ggplot2 documentation but didn't see…
rhh
  • 1,968
  • 3
  • 15
  • 13
117
votes
1 answer

ggplot2 plot area margins?

Is there an easy way to increase the space between the plot title and plot area below it (i.e., the box with the data). Similarly, I'd prefer to have some space between the axis title and axis labels. In other words, is there a way to "move the…
KT.
  • 10,815
  • 4
  • 47
  • 71
116
votes
9 answers

How can I extract plot axes' ranges for a ggplot2 object?

I have an object from ggplot2, say myPlot, how can I identify the ranges for the x and y axes? It doesn't seem to be a simple multiple of the data values' range, because one can rescale plots, modify axes' ranges, and so on. findFn (from sos) and…
Iterator
  • 20,250
  • 12
  • 75
  • 111
116
votes
7 answers

Explain ggplot2 warning: "Removed k rows containing missing values"

I get this warning when I am trying to generate a plot with ggplot. After researching online for a while many suggested that my database contains either null values or missing data in general, which was not the case. In this question the accepted…
ksm001
  • 3,772
  • 10
  • 36
  • 57
115
votes
3 answers

How can I manipulate the strip text of facet_grid plots?

I'm wondering how I can manipulate the size of strip text in facetted plots. My question is similar to a question on plot titles, but I'm specifically concerned with manipulating not the plot title but the text that appears in facet titles…
briandk
  • 6,749
  • 8
  • 36
  • 46
115
votes
5 answers

How do I arrange a variable list of plots using grid.arrange?

library(ggplot2) df <- data.frame(x=1:10, y=rnorm(10)) p1 <- ggplot(df, aes(x,y)) + geom_point() plist <- list(p1,p1,p1,p1,p1) # In my real example,a plot function will fit a ggplot to a list of datasets #and return a list of ggplots like the…
Maiasaura
  • 32,226
  • 27
  • 104
  • 108
114
votes
8 answers

Plot labels at ends of lines

I have the following data (temp.dat see end note for full data) Year State Capex 1 2003 VIC 5.356415 2 2004 VIC 5.765232 3 2005 VIC 5.247276 4 2006 VIC 5.579882 5 2007 VIC 5.142464 ... and I can produce the following…
Hugh
  • 15,521
  • 12
  • 57
  • 100
113
votes
2 answers

Combine legends for color and shape into a single legend

I'm creating a plot in ggplot from a 2 x 2 study design and would like to use 2 colors and 2 symbols to classify my 4 different treatment combinations. Currently I have 2 legends, one for the colors and one for the two shapes. How can I combine…
N Brouwer
  • 4,778
  • 7
  • 30
  • 35
113
votes
2 answers

How to change the default font size in ggplot2

I'd like to know if it is possible to change some default parameters of ggplot2 graphics, like font size for instance, for a whole R session. The idea is to avoid setting them for each plot.
jeannot
  • 1,255
  • 2
  • 9
  • 6
112
votes
9 answers

Left align two graph edges (ggplot)

I'm using ggplot and have two graphs that I want to display on top of each other. I used grid.arrange from gridExtra to stack them. The problem is I want the left edges of the graphs to align as well as the right edges regardless of axis labels. …
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519