ggplot2

How do I increase the number of evaluation points in geom_smooth for ggplot2 in R

I'm creating a plot and adding a basic loess smooth line to it. qplot(Age.GTS2004., X.d18O,data=deepsea, geom=c('point')) + geom_smooth(method="loess",se=T,span=0.01, alpha=.5, fill='light blue',color='navy') The problem is that the line is coming out really choppy. I need more evaluation point for the curve in certain areas. Is the...

subset in geom_point SOMETIMES returns full dataset, instead of none.

I ask the following in the hope that someone might come up with a generic description about the problem.Basically I have no idea whats wrong with my code. When I run the code below, plot nr. 8 turns out wrong. Specifically the subset in geom_point does not work the way it should. (update: With plot nr. 8 the whole dataset is plottet, in...

how to use ggplot conditional on data

I asked this question and it seams ggplot2 currently has a bug with empty data.frames. Therefore I am trying to check if the dataframe is empty, before I make the plot. But what ever I come up with, it gets really ugly, and doesn't work. So I am asking for your help. example data: SOdata <- structure(list(id = 10:55, one = c(7L, 8...

Changing text size on a ggplot bump plot

Hi, I'm fairly new to ggplot. I have made a bumpplot using code posted below. I got the code from someones blog - i've lost the link.... I want to be able to increase the size of the lables (here letters which care very small on the left and right of the plot) without affecting the width of the lines (this will only really make sense ...

ggplot2 footnote

What is the best way to add a footnote to the bottom of a plot created with ggplot2? I've tried using a combination of the logic noted here http://www.r-bloggers.com/r-good-practice-%E2%80%93-adding-footnotes-to-graphics/ as well as the ggplot2 annotate function p + annotate("text",label="Footnote", x=unit(1,"npc") - unit(2, "mm"),y=...

ggplot custom colors palette

Does anyone knows how to define a custom palette to be used in ggplot when geom="bar". I have an array of colors I would like to use: > rhg_cols [1] "#771C19" "#AA3929" "#E25033" "#F27314" "#F8A31B" "#E2C59F" "#B6C5CC" [8] "#8E9CA3" "#556670" "#000000" But When I try to pass it to nothing happened ggplot(mydata, aes(factor(phone_...

How to use ggplot2 make plot with 2 y axes, one y axis on the left, and another y axis on the right?

I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_bar), is overlapped by the second layer (i.e. the geom_line), can I move the axis of the geom_line to the right? Thanks! ...

How to "re-arrange" the legend in ggplot2?

I have a plot with several lines representing different columns of data, the legend is being arrange as a vertical column, but I want to place it at the bottom of the chart and arrange the keys horizontally, can it be done? Thanks! ...

Jitter plot in ggplot2, color by 1 variable, shade color by another variable?

Many hours of manic googling and leafing through ggplot2 documentation having brought me no closer, I was hoping someone could maybe nudge me in the right direction. I have cell count data for a few thousand subjects in a data.frame with the following layout: 1 subject per row. 1 column per cell type (5 total, each holding the percent...

Getting legend coloring in an empty ggplot

Before presenting the actual data, I would like to make a plot identical to the one with data but then without the data points in there. This helps me in explaining how to interpret such a plot without distracting the audience with the actual data that will be in the plot. So in the code below I would basically want to exchange the geom...

Error when running library(ggplot2)

Hello I just updated to R 2.11.1 and after installing ggplot2, I tried library(ggplot2) and got Loading required package: proto Loading required package: grid Loading required package: reshape Loading required package: plyr Loading required package: digest Error in eval(expr, envir, enclos) : could not find function ...

How to adjust the line width of colour in geom_box for ggplot2?

As title, I think the default line width for the border of geom_box is a bit too thick, is there a way of modifying it? Thanks! ...

How do I make the y-axis intersect the x-axis at 0 in ggplot2?

So when I make plots sometimes I see the y crossing x at some offset. I generated this figure using: ggplot(data=d2,aes(y=log10(Nems+1),x=Time)) + geom_point(size=3,shape=1) + geom_line(data=d2,aes(x=time_model,y=log10(value),group=variable,linetype=variable)) + ylim(0.001,2) + no_bg + draw_axis I end up manually moving ...

Grouped bar chart with ggplot2 and already tabulated data

I fit a count model to a vector of actual data and would now like to plot the actual and the predicted as a grouped (dodged) bar chart. Since this is a count model, the data are discrete (X=x from 0 to 317). Since I am fitting a model, I only have already-tabulated data for the predicted values. Here is how my original data frame looks:...

Is there a way to add a legend for ggplot's alpha?

I have a plot with many overlapping points (goes from 2-10). Adding jitter to the points makes it very noisy and unappealing. I like adding a alpha in the aesthetics. However, I'd like to have a legend where a reader can see how many points are overlapping for each of those transparencies. Is there such a way? ggplot(data=mydata,aes(x=x...

Is it possible to jitter two ggplot geoms in the same way?

Using position_jitter creates random jitter to prevent overplotting of data points. In the below I have used the example of baseball statistics to illustrate my problem. When I plot the same data with two layers, the same jitter call jitters the geoms a bit differently. This makes sense because it presumably generates the random jitter ...

R + ggplot: how to change options on a per-facet basis

Hi I'm using facets in ggplot2 to plot the distribution of expression in a large number of genes. My plotting commands are pretty generic: p <- ggplot(top_n,aes(x=value,fill=ptype)) p <- p + geom_density(alpha = 0.2) p <- p + facet_wrap(~probe,...) they just plot the data in top_n as distributions coloured according to the ptype varia...

Recreate ggplot's geom_smooth CI background - in R basic?

Hi all, I wish to recreate this graph: (from here) Using R base graphics. I have no clue how to do that. Any advice ? (My motivation is that I wish to create a plot where the line width (and/or color) will reflect another dimension. Until now - ggplot2 is the only place I found in R for how to do this. I would be happy to be able...

Why wont ggplot2 allow me to set a size for each individual point?

I've got a scatter plot. I'd like to scale the size of each point by its frequency. So I've got a frequency column of the same length. However, if I do: ... + geom_point(size=Freq) I get this error: When _setting_ aesthetics, they may only take one value. Problems: size which I interpret as all points can only have 1 size. So how w...

Loop in R to create and save series of ggplot2 plots with specified names

I have a data frame in R with POSIXct variable sessionstarttime. Each row is identified by integer ID variable of a specified location . Number of rows is different for each location. I plot overall graph simply by: myplot <- ggplot(bigMAC, aes(x = sessionstarttime)) + geom_freqpoly() Is it possible to create a loop that will create a...