Re: How to plot bar chart with data table

25 views
Skip to first unread message

Tina Young

unread,
Mar 26, 2013, 10:26:38 PM3/26/13
to ggp...@googlegroups.com
charts are attached.


2013/3/27 Tina Young <hotin...@gmail.com>
Hi,
Is it possible to plot similar chart as below? bar chart with data table, show the legend in the table.



 I used geom_bar, geom_line,geom_point and facet_grid...but how to plot the data table, show two Y axis, adjust the point color?

 library(ggplot2)
 df.test <- data.frame(Group=c(rep('A',5),rep('B',4)),Time=c(paste("WW",c(1:5,1,2,4,5),sep="")))

df.test1 <- df.test
df.test2 <- df.test
df.test3 <- df.test
df.test1$Data <- 1:9
df.test1$Class <- "data1"
df.test2$Data <- 2:10
df.test2$Class <- "data2"
df.test3$Sum <- 3:11
df.test <- rbind(df.test1,df.test2)
 df.test <- merge(df.test,df.test3)
 df.test
   Group Time Data Class Sum
1      A  WW1    1 data1   3
2      A  WW1    2 data2   3
3      A  WW2    3 data2   4
4      A  WW2    2 data1   4
5      A  WW3    4 data2   5
6      A  WW3    3 data1   5
7      A  WW4    5 data2   6
8      A  WW4    4 data1   6
9      A  WW5    5 data1   7
10     A  WW5    6 data2   7
11     B  WW1    7 data2   8
12     B  WW1    6 data1   8
13     B  WW2    8 data2   9
14     B  WW2    7 data1   9
15     B  WW4    9 data2  10
16     B  WW4    8 data1  10
17     B  WW5    9 data1  11
18     B  WW5   10 data2  11

p <- ggplot(data=df.test,aes(x=Time,y=Data,fill=factor(Class)))
p+geom_bar(position='stack',stat="identity")+geom_line(aes(x=Time,y=Sum,group=Group),colour="green",size=2,linetype=1)+geom_point(aes(x=Time,y=Sum,group=Group),colour="green",size=5,shape=23)+facet_grid(~Group)


Thanks!
Tina


Rplot.png
Capture1.PNG

Tina Young

unread,
Mar 26, 2013, 10:23:30 PM3/26/13
to ggp...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages