Bar graph with groups?

44 views
Skip to first unread message

Ignacio Martinez

unread,
Sep 27, 2013, 4:20:01 PM9/27/13
to ggp...@googlegroups.com
I have a data frame with 4 columns: "age", "treatment1", "treatment2", "control" This is a sample of my data:

x<-
structure(list(Age = c(24, 25, 39, 20, 33, 42, 33, 31, 22, 26, 
30, 19, 23, 30, 29, 49, 27, 38, 16, 38, 22, 19, 25, 36, 26, 47, 
54, 33, 33, 51, 26, 25, 31, 48, 28, 29, 21, 36, 23, 27, 50, 29, 
33, 22, 18, 24, 27, 34, 28, 35, 44, 35, 23, 25, 35, 27, 49, 49, 
22, 33, 26, 23, 32, 26, 40, 51, 22, 28, 23, 19, 19, 46, 28, 30, 
39, 30, 23, 35, 24, 32, 22, 25, 32, 46, 31, 30, 49, 33, 17, 27, 
46, 39, 35, 30, 32, 27, 54, 22, 36, 22), control = c(0L, 1L, 
0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 
1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 
0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 
1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 
1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 
0L, 1L), treatment1 = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 
1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 
0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 
0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 
1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 
1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L), treatment2 = c(1L, 0L, 
1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 
0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 
1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 
1L, 0L)), .Names = c("Age", "control", "treatment1", "treatment2"
), row.names = c(NA, -100L), class = "data.frame")

I would like to make a bar graph for the ages with separated bars for  "treatment1",  "treatment2", and "control"

How can I do this with ggplot2?

Thanks!

Ignacio Martinez

unread,
Sep 27, 2013, 6:30:58 PM9/27/13
to Vivek Patil, ggp...@googlegroups.com
That is exactly what i was trying to do

Thanks!


On Fri, Sep 27, 2013 at 6:18 PM, Vivek Patil <pat...@gmail.com> wrote:
Then is this it?

library(ggplot2)
library(reshape2)
xmelt=melt(x,id="Age")
xmeltNoZero=xmelt[which(xmelt$value==1),]
ggplot(xmeltNoZero,aes(x=Age,fill=variable))+geom_bar(stat="bin", position="dodge")


On Fri, Sep 27, 2013 at 3:09 PM, Ignacio Martinez <igna...@gmail.com> wrote:
That is not exactly what I had in mind. I want to have on the x axis age and on the y axis count. For each age, I want to have a separate bar for each group


On Fri, Sep 27, 2013 at 6:02 PM, Vivek Patil <pat...@gmail.com> wrote:
Is this what you need?

library(ggplot2)
library(reshape2)
library(plyr)
meanTable=ddply(x,.(control,treatment1,treatment2),summarize,meanAge=mean(Age))
meanTablemelt=melt(meanTable,id="meanAge")
ggplot(meanTablemelt[which(meanTablemelt$value==1),],aes(x=variable,y=meanAge)+geom_bar(stat="identity")


--
--
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
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Ignacio Martinez

unread,
Sep 27, 2013, 6:56:06 PM9/27/13
to Vivek Patil, ggp...@googlegroups.com
I'm trying to do a similar graph but the date is different enough that is proving difficult :_(

Instead of having age I have 6 dummy variables (can take the value 0 or 1). For each one of those i want to have a bar for each group, and on the y axis the count. Does it makes sense?

y<-structure(list(edu_sHS = structure(c(2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 
1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2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0L, 0L), treatment2 = c(1L, 
0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 
0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 
0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 
0L, 1L, 0L)), .Names = c("edu_sHS", "edu_HS", "edu_sC", "edu_BA", 
"edu_MA", "edu_PhD", "control", "treatment1", "treatment2"), row.names = c(1L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 
56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 
69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 
82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 
95L, 96L, 97L, 98L, 99L, 100L, 101L), class = "data.frame")

Thanks a lot for the help!

Vivek Patil

unread,
Sep 27, 2013, 6:18:20 PM9/27/13
to Ignacio Martinez, ggp...@googlegroups.com
Then is this it?

library(ggplot2)
library(reshape2)
xmelt=melt(x,id="Age")
xmeltNoZero=xmelt[which(xmelt$value==1),]
ggplot(xmeltNoZero,aes(x=Age,fill=variable))+geom_bar(stat="bin", position="dodge")
On Fri, Sep 27, 2013 at 3:09 PM, Ignacio Martinez <igna...@gmail.com> wrote:
That is not exactly what I had in mind. I want to have on the x axis age and on the y axis count. For each age, I want to have a separate bar for each group
On Fri, Sep 27, 2013 at 6:02 PM, Vivek Patil <pat...@gmail.com> wrote:
Is this what you need?

library(ggplot2)
library(reshape2)
library(plyr)
meanTable=ddply(x,.(control,treatment1,treatment2),summarize,meanAge=mean(Age))
meanTablemelt=melt(meanTable,id="meanAge")
ggplot(meanTablemelt[which(meanTablemelt$value==1),],aes(x=variable,y=meanAge)+geom_bar(stat="identity")
On Fri, Sep 27, 2013 at 1:20 PM, Ignacio Martinez <igna...@gmail.com> wrote:

--

Ignacio Martinez

unread,
Sep 27, 2013, 7:22:49 PM9/27/13
to Vivek Patil, ggp...@googlegroups.com



On Fri, Sep 27, 2013 at 7:15 PM, Vivek Patil <pat...@gmail.com> wrote:
The issue with this dataset is that different categorical vars don't appear to be mutually exclusive... so, unlike the earlier dataset x where an observation belonged to only one of the three categories, this dataset can have observations that belong to multiple categories. Is this what you're looking for? Have fun interpreting it.
I did something wrong when generating that data... they should be mutually exclusive. I guess I should add the question of how to generate "fake data" like the one i'm describing (but mutually exlusive). In a couple of days I'm going to get data like that from a survey, but for now i'm trying to figure out ggplot2 with fake data.

Thanks a lot again!
 
 
library(ggplot2)
library(reshape2)
y$dummy=0
ymelt=melt(y,id="dummy")
ggplot(ymelt[which(ymelt$value==1),],aes(variable))+geom_bar(stat="bin",position="dodge")

Ignacio Martinez

unread,
Oct 1, 2013, 10:27:59 AM10/1/13
to Vivek Patil, ggp...@googlegroups.com
Lets try again.

My data look like this

X<- structure(list(group = structure(c(3L, 3L, 1L, 3L, 2L, 3L, 1L,
1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
1L, 2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NA, 250L), class = "data.frame")

On the Y axis I want to have "count" on the X axis I want to have 3 bars for each education level (one for each group). So i have 3 bars for "edu_PhD", 3 for "edu_MA", etc.

How can I do this with ggplot2?

Thanks a lot!

Vivek Patil

unread,
Oct 1, 2013, 11:43:53 AM10/1/13
to Ignacio Martinez, ggp...@googlegroups.com
library(ggplot2)
ggplot(X,aes(x=Education,fill=group))+geom_bar(stat="bin",position="dodge")

Ignacio Martinez

unread,
Oct 1, 2013, 12:06:32 PM10/1/13
to Vivek Patil, ggp...@googlegroups.com
That was easier than expected!

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages