I am using R, I have a couple conditions with three replicates in each and I want to apply t.test to each of the elements in the conditions (the rows). For this I am willing to use apply function to the dataset (143,554 rows) containing all the info and specifying to retrieve the pval obtained by the t.test.
The columns 4,6,8 are the replicates for the first condition (main element of apply), the colums 10,12,14 are the elements of the second condition (example data at the end). And I thought that something like this could do the work:
t.test.10x = apply( MT.10x[,c(4,6,8)], 1, function(x) t.test(x, MT.10x[,c(10,12,14)])$p.value)
However this syntax is wrong because providing the whole table for the second condition in t.test will not go row by row, instead this approach will compare all the rows in 10,12,14 to each row in 4,6,8.
I don't want to use for loop but if it is absolutely required... well..
Thank you!!
Dataset example:
Chr Start End wt1_R wt1_T wt2_R wt2_T wt3_R wt3_T ko1_R ko1_T ko2_R ko2_T ko3_R ko3_T
chr1 3060417 3060419 0.0698 43 0.25 28 0.172 29 0.188 32 0.156 45 0.119 42
chr1 3060431 3060433 0.786 28 0.818 22 0.526 19 0.895 19 0.833 36 0.784 37
chr1 3168805 3168807 0.688 16 1 19 0.769 13 0.929 14 0.933 15 0.9 10
chr1 3228992 3228994 0.7 10 1 11 0.786 14 1 14 0.938 16 0.923 13
chr1 3233065 3233067 0.857 14 0.917 12 1 17 0.846 13 0.857 21 0.952 21
chr1 3265234 3265236 0.84 25 0.727 11 0.909 22 0.968 31 0.895 19 0.905 21
chr1 3265322 3265324 0.111 27 0.25 28 0.55 20 0.385 13 0.467 15 0.462 13
chr1 3265345 3265347 0.806 31 0.857 35 0.733 30 0.9 30 0.8 25 1 17
chr1 3265357 3265359 1 30 0.759 29 0.758 33 0.867 30 0.903 31 1 18
chr1 3265486 3265488 1 15 0.545 22 1 13 0.8 10 0.917 12 1 24
chr1 3265512 3265514 0.857 28 0.75 20 0.583 24 0.714 21 0.882 17 0.839 31
chr1 3265540 3265542 0.757 37 0.966 29 0.969 32 0.774 31 0.955 22 0.971 34
chr1 3265771 3265773 0.741 27 0.864 22 0.963 27 1 20 0.864 22 0.962 26
chr1 3265776 3265778 1 20 1 21 1 26 0.722 18 1 24 0.852 27
chr1 3265803 3265805 0.611 18 0.96 25 1 17 1 18 0.895 19 0.828 29
chr1 3760225 3760227 0.278 36 0.0741 27 0.417 24 0.158 19 0.4 40 0.136 22
chr1 3760285 3760287 0.851 47 0.711 38 0.867 15 0.81 21 0.914 35 0.893 28
chr1 3761299 3761301 0.786 14 0.885 26 1 11 0.929 14 0.771 35 0.75 24
chr1 3761414 3761416 0.706 17 1 17 0.545 22 0.857 14 0.818 11 0.8 15
chr1 3838606 3838608 0.806 31 0.692 13 0.611 18 1 11 1 23 1 11
chr1 3838611 3838613 0.767 30 1 13 0.947 19 0.818 11 1 20 1 11
chr1 4182108 4182110 0.231 13 0.5 14 0.143 21 0.0667 15 0.235 17 0.353 17
chr1 4547434 4547436 0.9 10 1 13 1 17 1 14 0.909 11 0.909 11
chr1 4547456 4547458 1 18 1 10 0.895 19 0.833 12 1 12 1 12
chr1 4547496 4547498 0.812 16 0.917 12 0.75 16 0.923 13 0.818 11 0.9 10
chr1 4547509 4547511 1 14 1 12 1 15 0.9 10 0.833 12 1 11
chr1 4547512 4547514 0.923 13 1 12 1 14 0.909 11 0.833 12 0.909 11
chr1 4765732 4765734 0 11 0 12 0 11 0 13 0 13 0.1 10
chr1 5185343 5185345 0.818 22 0.909 22 0.963 27 1 15 0.923 13 1 16
chr1 5185567 5185569 0.885 52 0.781 32 0.984 63 1 37 0.844 45 1 29
I think you are looking for mapply:
mapply(function(x,y)
t.test(x,y)$p.value,
MT.10x[,c(4,6,8)], MT.10x[,c(10,12,14)])
## wt1_R wt2_R wt3_R
## 0.4790554 0.8289961 0.5204527
Related
OD Graph Example
Let me preface by saying that I am new to R and have limited coding experience. I have a data.frame with 4 different variables, three of which are factors (replicate, dilution, and hours). My final variable is the optical density which I need as a number value.
I'm looking to graph the differences of optical density across dilution based on hours (think bar graph with positive and negative values based on dilution). The real problem for me is that I don't know how to separate my data based on hours so I can find the difference in the density between them. I feel like this is a simple task, but everywhere I've looked has let me down the wrong path.
Replicate pf_dilution hours OD
1 1 0 0 0.050
2 2 0 0 0.045
3 3 0 0 0.061
4 1 10 0 0.155
5 2 10 0 0.138
6 3 10 0 0.135
Further down the list hours go to 24 and later 48.
Graphing the data set
df %>%
group_by(hours) %>%
ggplot(aes(x = pf_dilution, y = OD)) +
geom_col(aes(fill = hours), position = position_dodge()) +
labs(title = "Optical Density of C. elegans against P. fluorescens ",
x = "PF Concentration [uL]",
y = "OD") +
scale_x_continuous(breaks = seq(0, 100, 10)) +
scale_fill_discrete(name = "Hours")
Data
df <- read.table(text = "
Replicate pf_dilution hours OD
1 0 0 0.05
2 0 0 0.045
3 0 0 0.061
1 10 0 0.155
2 10 0 0.138
3 10 0 0.135
1 20 0 0.234
2 20 0 0.212
3 20 0 0.23
1 30 0 0.31
2 30 0 0.278
3 30 0 0.279
1 40 0 0.372
2 40 0 0.392
3 40 0 0.367
1 50 0 0.426
2 50 0 0.464
3 50 0 0.443
1 60 0 0.524
2 60 0 0.546
3 60 0 0.544
1 70 0 0.624
2 70 0 0.587
3 70 0 0.55
1 80 0 0.638
2 80 0 0.658
3 80 0 0.658
1 90 0 0.721
2 90 0 0.711
3 90 0 0.711
1 100 0 0.791
2 100 0 0.791
3 100 0 0.784
1 0 24 0.059
2 0 24 0.065
3 0 24 0.063
1 10 24 0.132
2 10 24 0.106
3 10 24 0.108
1 20 24 0.186
2 20 24 0.158
3 20 24 0.184
1 30 24 0.235
2 30 24 0.206
3 30 24 0.191
1 40 24 0.263
2 40 24 0.296
3 40 24 0.255
1 50 24 0.304
2 50 24 0.333
3 50 24 0.329
1 60 24 0.358
2 60 24 0.414
3 60 24 0.414
1 70 24 0.512
2 70 24 0.438
3 70 24 0.438
1 80 24 0.509
2 80 24 0.487
3 80 24 0.481
1 90 24 0.573
2 90 24 0.528
3 90 24 0.525
1 100 24 0.633
2 100 24 0.602
3 100 24 0.607
1 0 48 0.473
2 0 48 0.392
3 0 48 0.486
1 10 48 0.473
2 10 48 0.473
3 10 48 0.491
1 20 48 0.466
2 20 48 0.437
3 20 48 0.487
1 30 48 0.469
2 30 48 0.435
3 30 48 0.424
1 40 48 0.431
2 40 48 0.439
3 40 48 0.414
1 50 48 0.42
2 50 48 0.423
3 50 48 0.402
1 60 48 0.42
2 60 48 0.523
3 60 48 0.53
1 70 48 0.531
2 70 48 0.464
3 70 48 0.45
1 80 48 0.502
2 80 48 0.511
3 80 48 0.482
1 90 48 0.549
2 90 48 0.516
3 90 48 0.488
1 100 48 0.627
2 100 48 0.562
3 100 48 0.583
",
header = TRUE,
colClasses = c("factor", "integer", "factor", "double")
)
Not sure if the title makes sense, but I am new to "R" and to say the least I am confused. As you can see in the code below I have multiple entries that have the same name. For example, time ON and sample 1 appears 3 times. I want to figure out how to calculate the average of the OD at time ON and sample 1. How do I go about doing this? I want to do this for all repeats in the data frame.
Thanks in advance! Hope my question makes sense.
> freednaod
time sample OD
1 ON 1 0.248
2 ON 1 0.245
3 ON 1 0.224
4 ON 2 0.262
5 ON 2 0.260
6 ON 2 0.255
7 ON 3 0.245
8 ON 3 0.249
9 ON 3 0.244
10 0 1 0.010
11 0 1 0.013
12 0 1 0.012
13 0 2 0.014
14 0 2 0.013
15 0 2 0.015
16 0 3 0.013
17 0 3 0.013
18 0 3 0.014
19 30 1 0.018
20 30 1 0.020
21 30 1 0.019
22 30 2 0.017
23 30 2 0.019
24 30 2 0.021
25 30 3 0.021
26 30 3 0.020
27 30 3 0.024
28 60 1 0.023
29 60 1 0.024
30 60 1 0.023
31 60 2 0.031
32 60 2 0.031
33 60 2 0.033
34 60 3 0.025
35 60 3 0.028
36 60 3 0.024
37 90 1 0.052
38 90 1 0.048
39 90 1 0.049
40 90 2 0.076
41 90 2 0.078
42 90 2 0.081
43 90 3 0.073
44 90 3 0.068
45 90 3 0.067
46 120 1 0.124
47 120 1 0.128
48 120 1 0.134
49 120 2 0.202
50 120 2 0.202
51 120 2 0.186
52 120 3 0.192
53 120 3 0.182
54 120 3 0.183
55 150 1 0.229
56 150 1 0.215
57 150 1 0.220
58 150 2 0.197
59 150 2 0.216
60 150 2 0.200
61 150 3 0.207
62 150 3 0.211
63 150 3 0.209
By converting the 'time' column to a factor with levels specified by the unique level, the output would be ordered in the same order as in the initial dataset
aggregate(OD~ sample + time, transform(freednaod,
time = factor(time, levels = unique(time))), mean)[c(2, 1, 3)]
Or using dplyr
library(dplyr)
freednaod %>%
group_by(time = factor(time, levels = unique(time)), sample) %>%
summarise(OD = mean(OD))
I am trying to reproduce a matrix plot on a book. Here is the plot on the book:
Here are my codes:
y=read.table("T1-2.dat");
colnames(y) <- c("density","mach-dir","cross-dir");
library(car);
scatterplotMatrix(y,smooth=F, regLine=F, var.labels=colnames(y), diagonal=list(method="boxplot"));
And this is what it looks like right now:
.
How can I delete the names from the diagonal and put them on the side of the table just like the one on the book.
Thanks in advance.
Data:
> y
density mach-dir cross-dir
1 0.801 121.41 70.42
2 0.824 127.70 72.47
3 0.841 129.20 78.20
4 0.816 131.80 74.89
5 0.840 135.10 71.21
6 0.842 131.50 78.39
7 0.820 126.70 69.02
8 0.802 115.10 73.10
9 0.828 130.80 79.28
10 0.819 124.60 76.48
11 0.826 118.31 70.25
12 0.802 114.20 72.88
13 0.810 120.30 68.23
14 0.802 115.70 68.12
15 0.832 117.51 71.62
16 0.796 109.81 53.10
17 0.759 109.10 50.85
18 0.770 115.10 51.68
19 0.759 118.31 50.60
20 0.772 112.60 53.51
21 0.806 116.20 56.53
22 0.803 118.00 70.70
23 0.845 131.00 74.35
24 0.822 125.70 68.29
25 0.971 126.10 72.10
26 0.816 125.80 70.64
27 0.836 125.50 76.33
28 0.815 127.80 76.75
29 0.822 130.50 80.33
30 0.822 127.90 75.68
31 0.843 123.90 78.54
32 0.824 124.10 71.91
33 0.788 120.80 68.22
34 0.782 107.40 54.42
35 0.795 120.70 70.41
36 0.805 121.91 73.68
37 0.836 122.31 74.93
38 0.788 110.60 53.52
39 0.772 103.51 48.93
40 0.776 110.71 53.67
41 0.758 113.80 52.42
And by the way, can we also display "Max, Med, Min" and the corresponding values on the diagonal as well? Thanks.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
In plotting a Scatter plot with ggplot the size argument in the aes() function in geom_point() function is ignored.
Below please find more information.
My dataframe is the following:
> actbins
Var1 Freq prprob ObsFreq Obsprob
1 (0,0.01] 997 0.005 17 0.01705115
2 (0.01,0.02] 1126 0.015 22 0.01953819
3 (0.02,0.03] 896 0.025 16 0.01785714
4 (0.03,0.04] 742 0.035 32 0.04312668
5 (0.04,0.05] 603 0.045 19 0.03150912
6 (0.05,0.06] 479 0.055 30 0.06263048
7 (0.06,0.07] 373 0.065 19 0.05093834
8 (0.07,0.08] 341 0.075 20 0.05865103
9 (0.08,0.09] 317 0.085 21 0.06624606
10 (0.09,0.1] 258 0.095 16 0.06201550
11 (0.1,0.11] 237 0.105 18 0.07594937
12 (0.11,0.12] 177 0.115 22 0.12429379
13 (0.12,0.13] 182 0.125 20 0.10989011
14 (0.13,0.14] 132 0.135 19 0.14393939
15 (0.14,0.15] 137 0.145 18 0.13138686
16 (0.15,0.16] 141 0.155 23 0.16312057
17 (0.16,0.17] 132 0.165 25 0.18939394
18 (0.17,0.18] 118 0.175 22 0.18644068
19 (0.18,0.19] 89 0.185 20 0.22471910
20 (0.19,0.2] 97 0.195 17 0.17525773
21 (0.2,0.21] 98 0.205 20 0.20408163
22 (0.21,0.22] 109 0.215 18 0.16513761
23 (0.22,0.23] 94 0.225 14 0.14893617
24 (0.23,0.24] 82 0.235 22 0.26829268
25 (0.24,0.25] 89 0.245 29 0.32584270
26 (0.25,0.26] 74 0.255 16 0.21621622
27 (0.26,0.27] 55 0.265 16 0.29090909
28 (0.27,0.28] 76 0.275 15 0.19736842
29 (0.28,0.29] 69 0.285 23 0.33333333
30 (0.29,0.3] 73 0.295 25 0.34246575
31 (0.3,0.31] 50 0.305 12 0.24000000
32 (0.31,0.32] 66 0.315 22 0.33333333
33 (0.32,0.33] 45 0.325 17 0.37777778
34 (0.33,0.34] 49 0.335 13 0.26530612
35 (0.34,0.35] 43 0.345 18 0.41860465
36 (0.35,0.36] 55 0.355 27 0.49090909
37 (0.36,0.37] 44 0.365 15 0.34090909
38 (0.37,0.38] 43 0.375 20 0.46511628
39 (0.38,0.39] 49 0.385 21 0.42857143
40 (0.39,0.4] 47 0.395 19 0.40425532
41 (0.4,0.41] 34 0.405 16 0.47058824
42 (0.41,0.42] 41 0.415 25 0.60975610
43 (0.42,0.43] 34 0.425 19 0.55882353
44 (0.43,0.44] 21 0.435 11 0.52380952
45 (0.44,0.45] 29 0.445 13 0.44827586
46 (0.45,0.46] 23 0.455 7 0.30434783
47 (0.46,0.47] 13 0.465 6 0.46153846
48 (0.47,0.48] 21 0.475 11 0.52380952
49 (0.48,0.49] 19 0.485 8 0.42105263
50 (0.49,0.5] 16 0.495 7 0.43750000
51 (0.5,0.51] 17 0.505 13 0.76470588
52 (0.51,0.52] 18 0.515 9 0.50000000
53 (0.52,0.53] 4 0.525 1 0.25000000
54 (0.53,0.54] 15 0.535 5 0.33333333
55 (0.54,0.55] 5 0.545 1 0.20000000
56 (0.55,0.56] 8 0.555 5 0.62500000
57 (0.56,0.57] 2 0.565 2 1.00000000
58 (0.57,0.58] 9 0.575 6 0.66666667
59 (0.58,0.59] 6 0.585 3 0.50000000
60 (0.59,0.6] 10 0.595 3 0.30000000
61 (0.6,0.61] 5 0.605 3 0.60000000
62 (0.61,0.62] 14 0.615 8 0.57142857
63 (0.62,0.63] 2 0.625 1 0.50000000
64 (0.63,0.64] 0 0.635 0 NaN
65 (0.64,0.65] 4 0.645 2 0.50000000
66 (0.65,0.66] 2 0.655 0 0.00000000
67 (0.66,0.67] 3 0.665 2 0.66666667
68 (0.67,0.68] 0 0.675 0 NaN
69 (0.68,0.69] 0 0.685 0 NaN
70 (0.69,0.7] 0 0.695 0 NaN
71 (0.7,0.71] 0 0.705 0 NaN
72 (0.71,0.72] 1 0.715 0 0.00000000
73 (0.72,0.73] 0 0.725 0 NaN
74 (0.73,0.74] 0 0.735 0 NaN
75 (0.74,0.75] 0 0.745 0 NaN
76 (0.75,0.76] 0 0.755 0 NaN
77 (0.76,0.77] 0 0.765 0 NaN
78 (0.77,0.78] 0 0.775 0 NaN
79 (0.78,0.79] 1 0.785 0 0.00000000
80 (0.79,0.8] 0 0.795 0 NaN
81 (0.8,0.81] 0 0.805 0 NaN
82 (0.81,0.82] 0 0.815 0 NaN
83 (0.82,0.83] 0 0.825 0 NaN
84 (0.83,0.84] 0 0.835 0 NaN
85 (0.84,0.85] 0 0.845 0 NaN
86 (0.85,0.86] 0 0.855 0 NaN
87 (0.86,0.87] 0 0.865 0 NaN
88 (0.87,0.88] 0 0.875 0 NaN
89 (0.88,0.89] 0 0.885 0 NaN
90 (0.89,0.9] 0 0.895 0 NaN
91 (0.9,0.91] 0 0.905 0 NaN
92 (0.91,0.92] 0 0.915 0 NaN
93 (0.92,0.93] 0 0.925 0 NaN
94 (0.93,0.94] 0 0.935 0 NaN
95 (0.94,0.95] 0 0.945 0 NaN
96 (0.95,0.96] 0 0.955 0 NaN
97 (0.96,0.97] 0 0.965 0 NaN
98 (0.97,0.98] 0 0.975 0 NaN
99 (0.98,0.99] 0 0.985 0 NaN
100 (0.99,1] 0 0.995 0 NaN
My code is the following:
ggplot(actbins, aes(x = prprob, y = Obsprob)) +
geom_point(aes(size = Freq), color = 'red', size = 2, alpha = 0.5)
The output is the following:
Scatter plot:
For some reason the size argument in the aes() function is ignored.
Could you please explain why this is the case and advise accordingly?
You have forced the size with size = 2. Remove that and you will get a graph like this.
ggplot(actbins, aes(x = prprob, y = Obsprob)) +
geom_point(aes(size = Freq), color = 'red', alpha = 0.5, show.legend = T)
I am trying to change the kind of characters used by lattice in an xyplot using the following data
> rate
Temp Rep Ind Week Weight Rate
1 9 1 B 1 2.6713 0.254
2 9 1 B 2 2.6713 0.076
3 9 1 B 6 2.6713 0.000
4 9 1 B 8 2.6713 0.000
5 9 1 MST 1 1.0154 0.711
6 9 1 MST 2 1.0154 0.137
7 9 1 MST 6 1.0154 0.000
8 9 1 MST 8 1.0154 0.000
9 9 1 MSCT 1 1.2829 0.447
10 9 1 MSCT 2 1.2829 0.345
11 9 1 MSCT 6 1.2829 0.000
12 9 1 MSCT 8 1.2829 0.000
13 9 1 MBT 1 1.8709 0.211
14 9 1 MBT 2 1.8709 0.255
15 9 1 MBT 6 1.8709 0.000
16 9 1 MBT 8 1.8709 0.000
17 9 1 MBCT 1 2.1388 0.230
18 9 1 MBCT 2 2.1388 0.281
19 9 1 MBCT 6 2.1388 0.000
20 9 1 MBCT 8 2.1388 0.000
21 9 2 S 1 0.8779 0.287
22 9 2 S 2 0.8779 0.065
23 9 2 S 6 0.8779 0.000
24 9 2 S 8 0.8779 0.000
25 9 2 MST 1 0.7196 0.197
26 9 2 MST 2 0.7196 0.193
27 9 2 MST 6 0.7196 0.000
28 9 2 MST 8 0.7196 0.000
29 9 2 MSCT 1 1.4773 0.198
30 9 2 MSCT 2 1.4773 0.233
31 9 2 MSCT 6 1.4773 0.000
32 9 2 MSCT 8 1.4773 0.000
33 9 2 MBT 1 3.4376 0.244
34 9 2 MBT 2 3.4376 0.123
35 9 2 MBT 6 3.4376 0.000
36 9 2 MBT 8 3.4376 0.000
37 9 2 MBCT 1 1.2977 0.514
38 9 2 MBCT 2 1.2977 0.118
39 9 2 MBCT 6 1.2977 0.000
40 9 2 MBCT 8 1.2977 0.000
41 12 1 B 1 3.8078 0.262
42 12 1 B 2 3.8078 0.328
43 12 1 B 6 3.8078 0.000
44 12 1 B 8 3.8078 0.000
45 12 1 MST 1 1.6222 0.294
46 12 1 MST 2 1.6222 0.213
47 12 1 MST 6 1.6222 0.000
48 12 1 MST 8 1.6222 0.000
49 12 1 MSCT 1 1.0231 0.358
50 12 1 MSCT 2 1.0231 0.281
51 12 1 MSCT 6 1.0231 0.000
52 12 1 MSCT 8 1.0231 0.000
53 12 1 MBT 1 1.2747 0.353
54 12 1 MBT 2 1.2747 0.254
55 12 1 MBT 6 1.2747 0.000
56 12 1 MBT 8 1.2747 0.000
57 12 1 MBCT 1 1.0602 0.390
58 12 1 MBCT 2 1.0602 0.321
59 12 1 MBCT 6 1.0602 0.000
60 12 1 MBCT 8 1.0602 0.000
61 12 2 S 1 0.2584 0.733
62 12 2 S 2 0.2584 0.444
63 12 2 S 6 0.2584 0.000
64 12 2 S 8 0.2584 0.000
65 12 2 MST 1 0.6781 0.314
66 12 2 MST 2 0.6781 0.421
67 12 2 MST 6 0.6781 0.000
68 12 2 MST 8 0.6781 0.000
69 12 2 MSCT 1 0.7488 0.845
70 12 2 MSCT 2 0.7488 0.661
71 12 2 MSCT 6 0.7488 0.000
72 12 2 MSCT 8 0.7488 0.000
73 12 2 MBT 1 1.1220 0.184
74 12 2 MBT 2 1.1220 0.305
75 12 2 MBT 6 1.1220 0.000
76 12 2 MBT 8 1.1220 0.000
77 12 2 MBCT 1 1.4029 0.338
78 12 2 MBCT 2 1.4029 0.410
79 12 2 MBCT 6 1.4029 0.000
80 12 2 MBCT 8 1.4029 0.000
81 15 1 B 1 3.7202 0.340
82 15 1 B 2 3.7202 0.566
83 15 1 B 6 3.7202 0.000
84 15 1 B 8 3.7202 0.000
85 15 1 MST 1 0.7914 0.668
86 15 1 MST 2 0.7914 0.903
87 15 1 MST 6 0.7914 0.000
88 15 1 MST 8 0.7914 0.000
89 15 1 MSCT 1 1.2503 0.266
90 15 1 MSCT 2 1.2503 0.402
91 15 1 MSCT 6 1.2503 0.000
92 15 1 MSCT 8 1.2503 0.000
93 15 1 MBT 1 0.7691 0.362
94 15 1 MBT 2 0.7691 0.850
95 15 1 MBT 6 0.7691 0.000
96 15 1 MBT 8 0.7691 0.000
97 15 1 MBCT 1 1.7025 0.232
98 15 1 MBCT 2 1.7025 0.462
99 15 1 MBCT 6 1.7025 0.000
100 15 1 MBCT 8 1.7025 0.000
101 15 2 S 1 0.6142 0.084
102 15 2 S 2 0.6142 0.060
103 15 2 S 6 0.6142 0.000
104 15 2 S 8 0.6142 0.000
105 15 2 MST 1 1.0184 0.318
106 15 2 MST 2 1.0184 0.638
107 15 2 MST 6 1.0184 0.000
108 15 2 MST 8 1.0184 0.000
109 15 2 MSCT 1 1.0176 0.177
110 15 2 MSCT 2 1.0176 0.343
111 15 2 MSCT 6 1.0176 0.000
112 15 2 MSCT 8 1.0176 0.000
113 15 2 MBT 1 1.6684 0.311
114 15 2 MBT 2 1.6684 0.461
115 15 2 MBT 6 1.6684 0.000
116 15 2 MBT 8 1.6684 0.000
117 15 2 MBCT 1 2.1278 0.201
118 15 2 MBCT 2 2.1278 0.489
119 15 2 MBCT 6 2.1278 0.000
120 15 2 MBCT 8 2.1278 0.000
121 18 1 B 1 3.0669 0.233
122 18 1 B 2 3.0669 0.482
123 18 1 B 6 3.0669 0.000
124 18 1 B 8 3.0669 0.000
125 18 1 MST 1 1.1641 0.208
126 18 1 MST 2 1.1641 0.201
127 18 1 MST 6 1.1641 0.000
128 18 1 MST 8 1.1641 0.000
129 18 1 MSCT 1 1.0183 0.108
130 18 1 MSCT 2 1.0183 0.303
131 18 1 MSCT 6 1.0183 0.000
132 18 1 MSCT 8 1.0183 0.000
133 18 1 MBT 1 1.2028 -0.041
134 18 1 MBT 2 1.2028 -0.004
135 18 1 MBT 6 1.2028 0.000
136 18 1 MBT 8 1.2028 0.000
137 18 1 MBCT 1 1.6395 0.072
138 18 1 MBCT 2 1.6395 0.234
139 18 1 MBCT 6 1.6395 0.000
140 18 1 MBCT 8 1.6395 0.000
141 18 2 S 1 0.5858 0.466
142 18 2 S 2 0.5858 0.336
143 18 2 S 6 0.5858 0.000
144 18 2 S 8 0.5858 0.000
145 18 2 MST 1 1.5694 0.272
146 18 2 MST 2 1.5694 0.257
147 18 2 MST 6 1.5694 0.000
148 18 2 MST 8 1.5694 0.000
149 18 2 MSCT 1 1.1295 0.523
150 18 2 MSCT 2 1.1295 0.521
151 18 2 MSCT 6 1.1295 0.000
152 18 2 MSCT 8 1.1295 0.000
153 18 2 MBT 1 1.7526 0.105
154 18 2 MBT 2 1.7526 0.118
155 18 2 MBT 6 1.7526 0.000
156 18 2 MBT 8 1.7526 0.000
157 18 2 MBCT 1 1.6924 0.320
158 18 2 MBCT 2 1.6924 0.387
159 18 2 MBCT 6 1.6924 0.000
160 18 2 MBCT 8 1.6924 0.000
the code for plotting is
rate$Temp <- as.character(rate$Temp)
rate$Week <- as.character(rate$Week)
rate$Rep <- as.character(rate$Rep)
xyplot(Rate~Weight|Rep+Temp, groups=Week, rate,auto.key=list(columns=2), as.table=TRUE, xlab="Weight (gr)", ylab="Rate (umol/L*gr)", main="All individuals and Treatments at all times")
But this gives me all the symbols as a O and I need to make each set plotted with a different symbol.
I like to use the theme mechanism to do this. The black and white theme, will do different symbols by default; you get it like this:
bwtheme <- standard.theme("pdf", color=FALSE)
Or you can start with the color theme and modify the points as you like, as follows.
mytheme <- standard.theme("pdf")
mytheme$superpose.symbol$pch <- c(15,16,17,3)
mytheme$superpose.symbol$col <- c("blue","red","green","purple")
p4 <- xyplot(Rate~Weight|Rep+Temp, groups=Week, data=rate,
as.table=TRUE,
xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
main="All individuals and Treatments at all times",
strip=strip.custom(strip.names=1),
par.settings=mytheme,
auto.key=list(title="Week", cex.title=1, space="right")
)
Or, if you'd rather have it all one line, just pass what you want to change to par.settings.
xyplot(Rate~Weight|Rep+Temp, groups=Week, data=rate,
as.table=TRUE,
xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
main="All individuals and Treatments at all times",
strip=strip.custom(strip.names=1),
par.settings=list(superpose.symbol=list(
pch=c(15,16,17,3),
col=c("blue","red","green","purple"))),
auto.key=list(title="Week", cex.title=1, space="right")
)
These solutions are recommended over changing col and pch directly because then they must also be changed when building the key.
Two other notes that you may find instructive: First, try using factor instead of as.character; this will sort your weeks in the proper order. You can do this with less typing using within.
rate <- within(rate, {
Temp <- factor(Temp)
Week <- factor(Week)
Rep <- factor(Rep)
}
Second, check out the useOuterStrips function in the latticeExtra package. In particular, if your original plot is saved as p, try
useOuterStrips(p, strip=strip.custom(strip.names=1),
strip.left=strip.custom(strip.names=1) )
I found a way of changing the characters without changing the theme, just by adding a bit more code to the plot as follows
xyplot(Rate~Weight|Rep+Temp, groups=Week, rate,
pch=c(15,16,17,3), #this defines the different plot symbols used
col=c("blue","red","green","purple"), # this defines the colos used in the plot
as.table=TRUE,
xlab="Weight (gr)", ylab="Rate (umol/L*gr)",
main="All individuals and Treatments at all times",
strip=strip.custom(strip.names=1), #this changes what is displayed in the strip
key= list(text=list(c("Week","1","2","6","8")),
points=list(pch=c(NA,15,16,17,3),col=c(NA,"blue","red","green","purple")),
space="right")#this adds a complete key
)