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
191
votes
7 answers

Remove 'a' from legend when using aesthetics and geom_text

How can I can remove the letter 'a' from the legend generated by this code? If I remove the geom_text, then the 'a' letter will not show in the legend. I want to keep geom_text, though. ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, …
user2700207
  • 1,953
  • 2
  • 12
  • 4
189
votes
8 answers

Ignore outliers in ggplot2 boxplot

How would I ignore outliers in ggplot2 boxplot? I don't simply want them to disappear (i.e. outlier.size=0), but I want them to be ignored such that the y axis scales to show 1st/3rd percentile. My outliers are causing the "box" to shrink so small…
Suraj
  • 35,905
  • 47
  • 139
  • 250
187
votes
4 answers

increase legend font size ggplot2

Is there a way to increase the font size in ggplot2? I think I need to specify something like legend.key.width = unit(2, "line") in the theme function, but that is used to adjust the keys in legends, not the font sizes. Thanks!
alittleboy
  • 10,616
  • 23
  • 67
  • 107
186
votes
2 answers

Editing legend (text) labels in ggplot

I have spent hours looking in the documentation and on StackOverflow, but no solution seems to solve my problem. When using ggplot I can't get the right text in the legend, even though it's in my dataframe. I have tried scale_colour_manual,…
user3633161
  • 1,963
  • 2
  • 12
  • 6
185
votes
6 answers

Adding a regression line on a ggplot

I'm trying hard to add a regression line on a ggplot. I first tried with abline but I didn't manage to make it work. Then I tried this... data =…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
185
votes
7 answers

How to change line width in ggplot?

Datalink: the data used My code: ccfsisims <- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_ConsIndex.csv", header=TRUE, sep=",", na.string="NA", dec=".",…
iouraich
  • 2,944
  • 5
  • 29
  • 40
184
votes
9 answers

ggplot2 plot without axes, legends, etc

I want to use bioconductor's hexbin (which I can do) to generate a plot that fills the entire (png) display region - no axes, no labels, no background, no nuthin'.
user1320487
  • 2,079
  • 3
  • 15
  • 9
182
votes
15 answers

Most underused data visualization

Histograms and scatterplots are great methods of visualizing data and the relationship between variables, but recently I have been wondering about what visualization techniques I am missing. What do you think is the most underused type of…
Ian Fellows
  • 17,228
  • 10
  • 49
  • 63
180
votes
3 answers

Reorder bars in geom_bar ggplot2 by value

I am trying to make a bar-plot where the plot is ordered from the miRNA with the highest value to the miRNA with the lowest. Why does my code not work? > head(corr.m) miRNA variable value 1 mmu-miR-532-3p pos 7 2 …
user3741035
  • 2,455
  • 4
  • 15
  • 20
178
votes
4 answers

Add legend to ggplot2 line plot

I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used library(ggplot2) ## edit from original post - removed lines that downloaded data…
pacomet
  • 5,011
  • 12
  • 59
  • 111
177
votes
10 answers

Force R to stop plotting abbreviated axis labels (scientific notation) - e.g. 1e+00

In ggplot2 how can I stop axis labels being abbreviated - e.g. 1e+00, 1e+01 along the x axis once plotted? Ideally, I want to force R to display the actual values which in this case would be 1,10. Any help much appreciated.
JPD
  • 2,561
  • 5
  • 22
  • 26
175
votes
3 answers

Remove space between plotted data and the axes

I have the following dataframe: uniq <- structure(list(year = c(1986L, 1987L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L,…
Jaap
  • 81,064
  • 34
  • 182
  • 193
172
votes
8 answers

Is there a way to change the spacing between legend items in ggplot2?

Is there a way to change the spacing between legend items in ggplot2? I currently have legend.position ="top" which automatically produces a horizontal legend. However, the spacing of the items is very close together and I am wondering how to…
overflowname
  • 1,993
  • 3
  • 13
  • 12
170
votes
2 answers

ggplot: How to increase spacing between faceted plots?

I have several faceted histograms (obtained with the command below) which are nicely plotted one under the other. I would like to increase the spacing between them, however, they are tight. I looked at the doc but didn't find a parameter for this.…
wishihadabettername
  • 14,231
  • 21
  • 68
  • 85
167
votes
7 answers

Saving grid.arrange() plot to file

I am trying to plot multiple plots using ggplot2, arranging them using grid.arrange(). Since I managed to find someone describing the exact problem I have, I have quoted from the problem description from link: When I use ggsave() after…
I Like to Code
  • 7,101
  • 13
  • 38
  • 48