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")
)
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've been working on a r function to filter a large data frame of baseball team batting stats by game id, (i.e."2016/10/11/chnmlb-sfnmlb-1"), to create a list of past team matchups by season.
When I use some combinations of teams, output is correct, but others are not. (output contains a variety of ids)
I'm not real familiar with grep, and assume that is the problem. I patched my grep line and list output together by searching stack overflow and thought I had it till testing proved otherwise.
matchup.func <- function (home, away, df) {
matchups <- grep(paste('[0-9]{4}/[0-9]{2}/[0-9]{2}/[', home, '|', away, 'mlb]{6}-[', away, '|', home, 'mlb]{6}-[0-9]{1}', sep = ''), df$game.id, value = TRUE)
df <- df[df$game.id %in% matchups, c(1, 3:ncol(df))]
out <- list()
for (n in 1:length(unique(df$season))) {
for (s in unique(df$season)[n]) {
out[[s]] <- subset(df, season == s)
}
}
return(out)
}
sample of data frame:
bat.stats[sample(nrow(bat.stats), 3), ]
date game.id team wins losses flag ab r h d t hr rbi bb po da so lob avg obp slg ops roi season
1192 2016-04-11 2016/04/11/texmlb-seamlb-1 sea 2 5 away 38 7 14 3 0 0 7 2 27 8 11 15 0.226 0.303 0.336 0.639 0.286 R
764 2016-03-26 2016/03/26/wasmlb-slnmlb-1 sln 8 12 away 38 7 9 2 1 1 5 2 27 8 11 19 0.289 0.354 0.474 0.828 0.400 S
5705 2016-09-26 2016/09/26/oakmlb-anamlb-1 oak 67 89 home 29 2 6 1 0 1 2 2 27 13 4 12 0.260 0.322 0.404 0.726 0.429 R
sample of errant output:
matchup.func('tex', 'sea', bat.stats)
$S
date team wins losses flag ab r h d t hr rbi bb po da so lob avg obp slg ops roi season
21 2016-03-02 atl 1 0 home 32 4 7 0 0 2 3 2 27 19 2 11 0.203 0.222 0.406 0.628 1.000 S
22 2016-03-02 bal 0 1 away 40 11 14 3 2 2 11 10 27 13 4 28 0.316 0.415 0.532 0.947 0.000 S
47 2016-03-03 bal 0 2 home 41 10 17 7 0 2 10 0 27 9 3 13 0.329 0.354 0.519 0.873 0.000 S
48 2016-03-03 tba 1 1 away 33 3 5 0 1 0 3 2 24 10 8 13 0.186 0.213 0.343 0.556 0.500 S
141 2016-03-05 tba 2 2 home 35 6 6 2 0 0 5 3 27 11 5 15 0.199 0.266 0.318 0.584 0.500 S
142 2016-03-05 bal 0 5 away 41 10 17 5 1 0 10 4 27 9 10 13 0.331 0.371 0.497 0.868 0.000 S
sample of good:
matchup.func('bos', 'bal', bat.stats)
$S
date team wins losses flag ab r h d t hr rbi bb po da so lob avg obp slg ops roi season
143 2016-03-06 bal 0 6 home 34 8 14 4 0 0 8 5 27 5 8 22 0.284 0.330 0.420 0.750 0.000 S
144 2016-03-06 bos 3 2 away 38 7 10 3 0 0 7 7 24 7 13 25 0.209 0.285 0.322 0.607 0.600 S
209 2016-03-08 bos 4 3 home 37 1 12 1 1 0 1 4 27 15 8 26 0.222 0.292 0.320 0.612 0.571 S
210 2016-03-08 bal 0 8 away 36 5 12 5 0 1 4 4 27 9 4 27 0.283 0.345 0.429 0.774 0.000 S
On the good it gives a list of matchups as it should, (i.e. S, R, F, D), on the bad it outputs by season, but seems to only give matchups by date and not team. Not sure what to think.
I think that the issue is that regex inside [] behaves differently than you might expect. Specifically, it is looking for any matches to those characters, and in any order. Instead, you might try
matchups <- grep(paste0("(", home, "|", away, ")mlb-(", home, "|", away, ")mlb")
, df$game.id, value = TRUE)
That should give you either the home or the away team, followed by either the home or away team. Without more sample data though, I am not sure if this will catch edge cases.
You should also note that you don't have to match the entire string, so the date-finding regex at the beginning is likely superfluous.
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
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
)