some help with a tree factor bar graph

55 views
Skip to first unread message

Paola Barriga

unread,
Jul 5, 2012, 12:54:34 PM7/5/12
to ggp...@googlegroups.com
Hello,

I am trying to put together a bar graph that includes two plant species and two ant species as categorical variables and d13C as a dependent variable. I have these variables in two locales. So I would like to have two charts that separates them by locale. I have tried this:

d13<-read.table(file="/Users/paolabarriga/Desktop/fake.txt",header=TRUE,sep="\t")

names(d13)

str(d13)

d13C<-ggplot(d13,aes(x=factor(plant),fill=factor(ant),y=dC,group=locale,colour=ant))+geom_bar(position='dodge')

d13C<-d13C+labs(x="Plant species",y="d13C")

d13C<-d13C+facet_wrap()

d13C


but, the dependent variable is not found. I cannot see what I am doing wrong. If someone can give me a hand, I would be very thankful!

Paola

--
Paola A. Barriga
Ph.D. Candidate
Department of Biological Sciences
SCEN 632
1 University of Arkansas
Fayetteville, AR 72701-1201
pba...@uark.edu
Lab:(479)575-6349
___________________________________
"When we face problems or disagreements today, 
we have to arrive at solutions through dialogue. 
Dialogue is the only appropriate method. One-sided 
victory is no longer acceptable. We must work to 
resolve conflicts in a spirit of reconciliation, 
always keeping others' interests in mind." Dalai Lama

fake.txt

adam.l...@pnc.com

unread,
Jul 5, 2012, 1:01:26 PM7/5/12
to Paola Barriga, ggp...@googlegroups.com
I think you just need to tell it what variable to facet it on:

ggplot(d13,aes(plant,dC,colour=ant,fill=ant))+
geom_bar(position="dodge")+
facet_wrap(~locale)





Adam Loveland



From: Paola Barriga <paoba...@gmail.com>
To: ggp...@googlegroups.com
Date: 07/05/2012 12:54 PM
Subject: some help with a tree factor bar graph
Sent by: ggp...@googlegroups.com


--
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[attachment "fake.txt" deleted by Adam Loveland/FinAdmin/CLE/PNC]


The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any additional advertising or promotional messages from PNC at this e-mail address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp
By unsubscribing to this message, you will be unsubscribed from all advertising or promotional messages from PNC. Removing your e-mail address from this mailing list will not affect your subscription to alerts, e-newsletters or account servicing e-mails.


Paola Barriga

unread,
Jul 5, 2012, 2:36:13 PM7/5/12
to adam.l...@pnc.com, ggp...@googlegroups.com
Thanks Adam,

but the code you suggest for whatever reason now says that: Error in +geom_bar(position = "dodge") : 
  invalid argument to unary operator
> 

So, it is not working.

Paola

adam.l...@pnc.com

unread,
Jul 5, 2012, 2:40:11 PM7/5/12
to Paola Barriga, ggp...@googlegroups.com
Strange. It works for me:

d13 <- structure(list(locale = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L), .Label = c("L1", "L2"), class = "factor"),
    plant = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L), .Label = c("p1", "p2"), class = "factor"),
    ant = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 2L), .Label = c("a1", "a2"), class = "factor"),
    dC = c(-31.59, -31.49, -32.21, -30.15, -31.8, -31.1, -30.32,
    -31.66, -31.5, -31.25, -31.06, -31.02, -32.39, -29.94, -28.73,
    -32.72, -28.98, -30.22, -28.9, -29.55, -28.59, -27.83, -28.48,
    -30.09, -29.48, -28.81, -32, -29.24, -28.72, -30.26, -30.01,
    -29.88, -29.64, -30.12, -29.45, -29.74, -27.95, -29.5, -25.96,
    -28.72, -26.91, -29.86, -32.16, -29.48)), .Names = c("locale",
"plant", "ant", "dC"), class = "data.frame", row.names = c(NA,
-44L))

ggplot(d13,aes(plant,dC,colour=ant,fill=ant))+geom_bar(position="dodge")+facet_wrap(~locale)



Adam Loveland


From: Paola Barriga <paoba...@gmail.com>
To: adam.l...@pnc.com
Cc: ggp...@googlegroups.com
Date: 07/05/2012 02:36 PM
Subject: Re: some help with a tree factor bar graph
Sent by: ggp...@googlegroups.com

Ben Bond-Lamberty

unread,
Jul 5, 2012, 2:42:52 PM7/5/12
to ggp...@googlegroups.com
Yes, works for me too.
Ben

adam.l...@pnc.com

unread,
Jul 5, 2012, 3:05:47 PM7/5/12
to Paola Barriga, ggp...@googlegroups.com
The code does work. It's just that for your data, a bar chart isn't appropriate.

It's hard to know what is appropriate without knowing more about what you're trying to learn, but something along the lines of a boxplot or pointrange may be a more appropriate choice:

ggplot(d13,aes(plant,dC,colour=ant,fill=ant))+geom_boxplot()+ facet_wrap(~locale)




Adam Loveland


From: Paola Barriga <paoba...@gmail.com>
To: adam.l...@pnc.com
Date: 07/05/2012 02:51 PM
Subject: Re: some help with a tree factor bar graph





thanks anyways. For me does not work. I obtain only two bars when I need four. I do not really understand why it is not working.

Paola
Reply all
Reply to author
Forward
0 new messages