Heather,
Working backwards through your questions: qplot is just a convenient
wrapper for ggplot and its related functions. I use it frequently for
quick looks at things, but to build up a complex plot, you'll probably
want to use ggplot.
In your example, you're pulling data out of the data frame to plot it.
Don't! Keeping things in a single df makes things easier.
I think you want to do something like this:
qplot(rank,logabun,data=sp52,label=species,geom=c("text"))
Here, you're telling qplot to plot rank (x) versus logabun (y), with
labels pulled from species, and use geom_text. If you wanted to have
points as well as lines, you'd change that last part to
geom=c("point","text"). Alternatively, using ggplot:
ggplot( sp52, aes( rank, logabun ) ) + geom_text( aes( label=species ) )
Hope this is useful,
Ben
On Mon, Nov 12, 2012 at 12:40 PM, Heather Wright
<
heather...@maine.edu> wrote:
> Hi ggplot2 users, I want to add species labels (text) to an existing plot
> using geom_text and I don't know how to specify the layer from a colum of
> text names.
> Here's a visual example of what I'm trying to do:
>
http://docs.ggplot2.org/current/geom_text.html
>
> My data matrix consists of rank abundance data with an initial column
> containing the species names. I'm only interested in plotting rank vs.
> logabun and putting the text of each corresponding species near the data
> point. My question is: do I have to add each species as a new layer when I
> define geom_text() ?
>
> I am using R Studio on windows 7 32-bit
> Rstudio: Version 0.97.168
> R version 2.15.0 (2012-03-30)
> Input data: sp52.csv
> ---------------------------------------------------------------------------
> #reproducible code using .csv data
> sp52 <- read.csv("sp52.csv",header=TRUE, sep=",")
> rank<-sp52$rank
> logabun<-sp52$logabun
> species<-sp52$species
> str(sp52)
> data.frame': 52 obs. of 9 variables:
> $ species : Factor w/ 52 levels "Asterionellopsis.glacialis",..: 16 45 29
> 15 44 2 22 38 37 49 ...
> $ rank : int 3 4 5 6 8 11 12 13 14 15 ...
> $ abundance : num 825507 759812 526840 264905 159652 ...
> $ proportion: num 8.5 7.9 5.4 2.7 1.7 1.4 1.3 1.2 1.2 1.2 ...
> $ plower : num 7 6 4.5 1.9 1 0.6 0.6 0.8 0.9 0.8 ...
> $ pupper : num 10.1 9.7 6.4 3.6 2.3 2.2 2 1.6 1.5 1.5 ...
> $ accumfreq : num 56.3 64.2 69.6 72.3 75.7 80.2 81.5 82.7 83.9 85.1 ...
> $ logabun : num 5.9 5.9 5.7 5.4 5.2 5.1 5.1 5.1 5.1 5.1 ...
> $ rankfreq : num 0.9 1.2 1.5 1.7 2.3 3.2 3.5 3.8 4.1 4.4 ..
>
> #plot
> qplot(rank,logabun)
> #result file: qplot_logabun.rank_52sp.png
> # add species label to each point
> ggplot(sp52, aes(x=rank, y=logabun, label=rownames(species)))
>
> #alternately
> ggplot(sp52, aes(x=rank,y=logabun, label=species[1:52]))
> Error: No layers in plot
>
> Obviously, I need to define my layers using geom_text().
> If this is the case, do I need to specify the x,y values from the list of
> species for each discrete species label?
> Example:
>> sp52_plot <- ggplot(aes(x=3, y=5.9, label="Chaetoceros.tenuissimus"))
> Error: ggplot2 doesn't know how to deal with data of class uneval
>
> Any insight into geom_text() for this? and should I use ggplot or qplot?
> Thanks
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2