ggplot2

How can I add a subtitle and change the font size of ggplot plots in R?

I tried adding a subtitle using +opts(subtitle="text") but nothing showed up. The main title does work (+opts(title="text")). I would also like to use a larger font for the axis (labels and coordinates), but I can't tell how to do that. ...

Controlling relative size of points in ggplot2 plots

I need to draw many different tile plots, which have squares and dots on top of the tiles according to data. Unfortunately I cannot include illustrating picture, but basically the plot consist of tiles which either have squares and dots on them or not. Each of those figures has different number of tiles on x-direction and y-direction....

Calculating an area under a continuous density plot

I have two density curves plotted using this: Network <- Mydf$Networks quartiles <- quantile(Mydf$Avg.Position, probs=c(25,50,75)/100) density <- ggplot(Mydf, aes(x = Avg.Position, fill = Network)) d <- density + geom_density(alpha = 0.2) + xlim(1,11) + opts(title = "September 2010") + geom_vline(xintercept = quartiles, colour = "red"...

time series in R

hello, here is my question: i have these data summary(data) Date 1990/01: 1 1990/02: 1 1990/03: 1 1990/04: 1 1990/05: 1 1990/06: 1 (Other):242 attribute Min. :164.9 1st Qu.:201.5 Medi...

How to use ggplot to plot probablity densities?

Hi, I am looking for the ggplot way to plot a probability density function (or any function). I used to use the old plot() function in R to do this. For example, to plot a beta distribution with alpha=1 and beta=1 (uniform): x <- seq(0,1,length=100) db <- dbeta(x, 1, 1) plot(x, db, type='l') How can I do it in ggplot? Thank you! ...

How do I resuscitate a ggplot that was saved to disk inside a list?

I created several hundred plots using ggplot and saved them all to a list. I saved the list to disk using: save(list_of_plots,file="list_of_plots.rdata") Now I want to display those plots and save some using ggsave. However, calling a list item just shows me components of the plot. > names(plots00_t2[[1]]) [1] "data" "layers"...

Removing the zero level of an imagemap using ggplot2

I'm using the geom_tile to draw an imagemap and want to clear out the zero level for clarity. #dummy data set.seed(1) tdata <- data.frame(cat1=rep(letters[1:3],4),cat2=sort(rep(LETTERS[1:4],3)),val=rpois(12,1.5)) tdata$val<-tdata$val/max(tdata$val) I have found 2 ways to do this but both have their drawbacks: 1) qplot(cat1,cat2,data...

Recreate minitab normal probability plot

I am trying to recreate the following plot with R. Minitab describes this as a normal probability plot. The probplot gets you most of the way there. Unfortunately, I cannot figure out how to add the confidence interval bands around this plot. Similarly, ggplot's stat_qq() seems to present similar information with a transformed x axis...

ggplot2: aspect_ratio and placing title/axis label in the right place

Using ggplot2 under R (and the code below uses rpy2, I don't actually know straight R, sorry). I'm trying to add an aspect_ratio to my plot (so it'll fit nicely on a slide). The below example is pretty minimal. Aspect_ratio does the right thing EXCEPT the title and x-axis label are placed way above and below the plot, respectively, with...

[R] Wondering how to output a chart I saw in the economist magazine

I saw this in a recent economist and I was wondering if anyone has code that would help replicate it using ggplot. Economist Chart Thanks! ...

How to alter default fill settings for geom_bar plot

Greetings, I am trying to create a bar chart of the data posted below (referred to in my code as topTwoTable), disaggregated by group type. I've scanned through multiple online forums, as well as Hadley's website, and stuck when it comes to manually altering the fill color of the bars on the basis of treatment type. ...

Network Graph and US Map in R

Hi all, I created a network graph from data on flows between US states. For each vertex, I have the lat/long of the state. I am hoping to recreate a network kind of graph that shows the edges, except that I set the location of each vertex to be their geographic position and have a state boundary map in the background. I am using to ...

Incompatibility between ggplot2 and other packages in R?

I am revising a paper for submission and would like to replace the old lattice graphics with shiny new ggplot2 versions. However, I run into compatibility problems between ggplot2 and two packages that are absolutely crucial for my analyses, coin and arm. When executing the following example from the manual qplot(sleep_rem / sleep_total...

Plot a point in a contour plot ggplot2

Hi. I have a contour plot in ggplot2 that I want to map one point to. My contour plot looks like this: v = ggplot(pts, aes(theta_1, theta_2, z = z)) v + stat_contour(aes(colour = ..level..),bins=50) + xlab(expression(Theta[1])) + ylab(expression(Theta[2])) and I have a point that looks like this: p = ggplot(ts,aes(x,y)) p + geom_p...

Joining means on a boxplot with a line (ggplot2)

I have a boxplot showing multiple boxes. I want to connect the mean for each box together with a line. The boxplot does not display the mean by default, instead the middle line only indicates the median. I tried ggplot(data, aes(x=xData, y=yData, group=g)) + geom_boxplot() + stat_summary(fun.y=mean, geom="line") This does ...

Unwanted items on a plot

I have a problem while using a subset of a data.frame in R. The subset gets created and displayed correctly, but when I try to plot it using qplot(), the rows which were not selected by the subset() also get shown along one axis. The actual file I am reading in is a web server log, but I have created a small example to illustrate my pr...

How to format number values for ggplot2 legend?

I am working on finishing up a graph generated using ggplot2 like so... ggplot(timeSeries, aes(x=Date, y=Unique.Visitors, colour=Revenue)) + geom_point() + stat_smooth() + scale_y_continuous(formatter=comma) I have attached the result and you can see the numeric values in the legend for Revenue do not have a comma. How can I add a co...

How to order breaks with ggplot / geom_bar

I have a data.frame with entries like: variable importance order 1 foo 0.06977263 1 2 bar 0.05532474 2 3 baz 0.03589902 3 4 alpha 0.03552195 4 5 beta 0.03489081 5 ... When plotting the above, with the breaks = variable, I would like for the order to be preserved, rather t...

align axes in double plot ggplot R

How can I align the two ggplots in the following function so that the x-axis is corresponding between the table and the graph ? As it is now the interval between the "ticks" is less in the table. Any ideas? //M Edit: Forgot to give credit to the learnr website for the table plotting method.... function ggkm: ggkm<-function(time,event...

Restrict y-axis range on ggplot+geom_density

I'm using geom_density to plot densities with very thin tails. I want to restrict the y-axis range (so the top of the distribution will be off screen and the tail is more clearly visible) but it's throwing away data that is off-screen when it calculate the density, rather than just not showing what is off screen. E.g. This plots the f...