Hello,
I have a set of elements with two values each, I want to plot the sum
of the values for each element. I know that I must use stat_sum(),
but I don't know yet how to use it. I know that it is a trivial
question but looking at
http://docs.ggplot2.org/0.9.3/geom_point.html
http://docs.ggplot2.org/0.9.3/stat_sum.html
does not help for me (due my limited knowledge of ggplot2). Could
someone be so kind of provide me with an example for this kind of
plot?
A reproducible example is here:
seed(1234)
a <- rep(letters[seq( from = 1, to = 10 )],2)
b <- as.factor(rep(c(rep(1,10),rep(2,10)),2))
c <- sort(rnorm(mean=10,sd=0.7,n=40))
d <- c(rep("set1",20), rep("set2", 20))
test <- data.frame(a,b,c,d)
test
str(test)
# ploting the two values because I don't know yet how to use stat_sum()
ggplot(data=test)+geom_point(aes(x=a, y=c))+facet_wrap(~ d,
scales='free_x')+theme(axis.text.x = element_text(angle=90,
vjust=0.5))
> test
a b c d
1 a 1 8.282620 set1
2 b 1 8.792361 set1
3 c 1 8.996060 set1
4 d 1 9.019109 set1
5 e 1 9.143176 set1
6 f 1 9.181912 set1
7 g 1 9.233689 set1
8 h 1 9.281759 set1
9 i 1 9.396200 set1
10 j 1 9.585462 set1
11 a 2 9.611895 set1
12 b 2 9.650710 set1
13 c 2 9.684096 set1
14 d 2 9.690544 set1
15 e 2 9.714397 set1
16 f 2 9.730615 set1
17 g 2 9.919336 set1
18 h 2 9.972034 set1
19 i 2 10.118430 set1
20 j 2 10.121863 set1
21 a 1 10.122222 set2
22 b 1 10.124027 set2
23 c 1 10.206344 set2
24 d 1 10.213873 set2
25 e 1 10.262236 set2
26 f 1 10.345095 set2
27 g 1 10.356549 set2
28 h 1 10.369448 set2
29 i 1 10.411919 set2
30 j 1 10.429783 set2
31 a 2 10.589949 set2
32 b 2 10.654281 set2
33 c 2 10.680950 set2
34 d 2 10.874659 set2
35 e 2 10.877735 set2
36 f 2 10.958514 set2
37 g 2 10.978281 set2
38 h 2 11.158989 set2
39 i 2 11.186938 set2
40 j 2 11.323160 set2
Thanks
--
- Pablo Marin-Garcia