ggplot2 is an actively maintained open-source chart-drawing library 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.
23
votes
3answers
12k views
Order Bars in ggplot2 bar graph
I am trying to make a bar graph where the largest bar would be nearest to the y axis and the shortest bar would be furthest. So this is kind of like theTable I have
Name Position
1 James ...
14
votes
3answers
867 views
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 ...
20
votes
3answers
11k views
ggplot2: Adding Regression Line Equation and R2 on graph
I wonder how to add regression line equation and R^2 on the ggplot. My code is
library(ggplot2)
df <- data.frame(x = c(1:100))
df$y <- 2 + 3 * df$x + rnorm(100, sd = 40)
p <- ggplot(data = ...
12
votes
1answer
2k views
ggplot's qplot does not execute on sourcing
Let's assume I have 2 source files, the first one named example1.r and the second one example2.r (given below).
example1.r
plot(1:10,1:10)
example2.r
qplot(1:10,1:10)
When I source example1.r, ...
18
votes
2answers
994 views
Combine base and ggplot graphics in R figure window
I would like to generate a figure that has a combination of base and ggplot graphics. The following code shows my figure using the base plotting functions of R:
t <- c(1:(24*14))
P <- 24
A ...
10
votes
1answer
1k views
Generate multiple graphics from within an R function
I'd like to spawn several graphics windows from within a function in R using ggplot graphics...
testf <- function(a, b) {
devAskNewPage(TRUE)
qplot(a, b);
# grid.newpage(recording = TRUE)
...
50
votes
7answers
14k views
List of ggplot2 options?
After some research I found the way to prevent an uninformative legend from displaying
... + opts(legend.position = "none")
Where can I find all the available "opts" for ggplot2?
17
votes
2answers
8k views
ggplot: showing % instead of counts in charts of categorical variables
I'm plotting a categorical variable and instead of showing the counts for each category value,
I'm looking for a way to get ggplot to display the percentage of values in that category. Of course, it ...
8
votes
1answer
6k views
Showing data values on stacked bar chart in ggplot2
I'd like to show data values on stacked bar chart in ggplot2. Here is my attempted code
Year <- c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4))
Category <- c(rep(c("A", ...
6
votes
3answers
6k views
how to change the order of a discrete x scale in ggplot?
I am making a dodged bar chart using ggplot with discrete x scale, the x axis are now arranged in alphabetical order, but I need to rearrange it so that it is ordered by the value of the y-axis (i.e., ...
9
votes
1answer
4k views
How to change the order of facet labels in ggplot (custom facet wrap labels)
Hi I plotted a facet plot using ggplot in R and here is the plot
The problem I have is, The facets(labels) are sorted alphabetically (Ex: E1, E10, E11,E13, E2, E3, I1, I10, I2) but I need them to ...
251
votes
6answers
22k views
How can we make xkcd style graphs in R?
Apparently, folk have figured out how to make xkcd style graphs in Mathematica and in LaTeX. Can we do it in R? Ggplot2-ers? A geom_xkcd and/or theme_xkcd?
I guess in base graphics, par(xkcd=TRUE)? ...
18
votes
2answers
1k views
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 <- ...
11
votes
1answer
5k views
How to use Greek symbols in ggplot2?
My categories need to be named with Greek letters. I am using ggplot2, and it works beautifully with the data. Unfortunately I cannot figure out how to put those greek symbols on the x axis (at the ...
15
votes
3answers
3k views
Reproducing lattice dendrogram graph with ggplot2
Is this possible to reproduce this lattice plot with ggplot2?
library(latticeExtra)
data(mtcars)
x <- t(as.matrix(scale(mtcars)))
dd.row <- as.dendrogram(hclust(dist(x)))
row.ord <- ...