Highlight several specific points using ggplot 2 - r

My other Questions was marked as an duplicate (I used a common example, not my real data), therefore I opened a new one.
So again, I hope this time it becomes clear, what my problem is.
I have following data frame called "sample" (it´s extracted from my real dataframe):
county testscr str
1 Alameda 690.80 17.88991
2 Butte 661.20 21.52466
3 Butte 643.60 18.69723
4 Butte 647.70 17.35714
5 Butte 640.85 18.67133
6 Fresno 605.55 21.40625
7 San Joaquin 606.75 19.50000
8 Kern 609.00 20.89412
9 Fresno 612.50 19.94737
10 Sacramento 612.65 20.80556
11 Merced 615.75 21.23809
12 Fresno 616.30 21.00000
13 Tulare 616.30 20.60000
14 Tulare 616.30 20.00822
15 Tulare 616.45 18.02778
16 Tulare 617.35 20.25196
17 Kern 618.05 16.97787
18 Kern 618.30 16.50980
19 Los Angeles 619.80 22.70402
20 Kern 620.30 19.91111
I have plotted the variable testscr against str and added a linear Regression line to the plot using ggplot
ggplot(data=sample,aes(x=str,y=testscr))+
geom_point()+
geom_smooth(method="lm")
Now I want to highlight/color all points, which have "Butte", "Los Angeles" and "Fresno" as County value. All three of them should have different Colors and the rest of the points should be black.
dput(sample)
structure(list(county = structure(c(1L, 2L, 2L, 2L, 2L, 6L, 29L,
11L, 6L, 25L, 19L, 6L, 42L, 42L, 42L, 42L, 11L, 11L, 15L, 11L,
9L, 42L, 11L, 42L, 19L, 42L, 20L, 11L, 42L, 42L, 28L, 20L, 15L,
20L, 27L, 15L, 19L, 6L, 31L, 11L, 44L, 19L, 11L, 11L, 24L, 15L,
33L, 11L, 11L, 33L, 15L, 16L, 20L, 32L, 15L, 15L, 15L, 25L, 20L,
44L, 42L, 25L, 22L, 12L, 12L, 11L, 15L, 12L, 28L, 37L, 11L, 15L,
12L, 19L, 32L, 27L, 4L, 8L, 36L, 36L, 44L, 6L, 19L, 19L, 6L,
27L, 24L, 15L, 11L, 42L, 25L, 13L, 33L, 2L, 31L, 42L, 15L, 9L,
9L, 15L, 11L, 11L, 39L, 18L, 27L, 26L, 15L, 2L, 11L, 44L, 6L,
15L, 16L, 22L, 42L, 33L, 9L, 28L, 35L, 42L, 40L, 42L, 6L, 20L,
42L, 24L, 37L, 15L, 40L, 31L, 36L, 11L, 38L, 43L, 31L, 5L, 19L,
29L, 6L, 25L, 38L, 19L, 44L, 8L, 8L, 28L, 13L, 8L, 44L, 40L,
25L, 29L, 36L, 38L, 6L, 22L, 22L, 12L, 42L, 28L, 35L, 19L, 39L,
28L, 15L, 11L, 39L, 28L, 27L, 22L, 37L, 35L, 40L, 43L, 36L, 8L,
4L, 43L, 23L, 37L, 37L, 38L, 35L, 8L, 42L, 7L, 37L, 14L, 9L,
14L, 22L, 37L, 32L, 8L, 39L, 35L, 11L, 28L, 34L, 24L, 11L, 33L,
9L, 29L, 40L, 8L, 35L, 15L, 21L, 42L, 11L, 25L, 26L, 28L, 39L,
6L, 4L, 36L, 29L, 33L, 12L, 38L, 29L, 23L, 26L, 5L, 27L, 35L,
21L, 31L, 12L, 35L, 3L, 17L, 28L, 33L, 39L, 21L, 8L, 37L, 31L,
40L, 22L, 27L, 15L, 8L, 27L, 30L, 33L, 5L, 15L, 10L, 32L, 16L,
36L, 37L, 21L, 42L, 42L, 43L, 15L, 19L, 31L, 33L, 37L, 11L, 31L,
43L, 23L, 38L, 14L, 35L, 42L, 15L, 33L, 15L, 37L, 11L, 35L, 23L,
36L, 37L, 16L, 8L, 5L, 37L, 40L, 37L, 37L, 23L, 34L, 8L, 27L,
23L, 5L, 22L, 7L, 31L, 32L, 27L, 37L, 33L, 32L, 28L, 22L, 32L,
34L, 7L, 37L, 21L, 12L, 28L, 14L, 44L, 43L, 36L, 37L, 28L, 37L,
8L, 11L, 42L, 33L, 11L, 12L, 28L, 28L, 42L, 28L, 22L, 15L, 15L,
17L, 33L, 40L, 8L, 28L, 35L, 11L, 33L, 22L, 5L, 5L, 23L, 5L,
8L, 15L, 23L, 23L, 37L, 31L, 21L, 16L, 30L, 14L, 6L, 37L, 37L,
31L, 5L, 23L, 28L, 5L, 21L, 37L, 8L, 41L, 21L, 23L, 44L, 41L,
35L, 21L, 8L, 37L, 28L, 17L, 33L, 15L, 37L, 20L, 37L, 33L, 37L,
37L, 38L, 17L, 32L, 37L, 17L, 34L, 31L, 35L, 34L, 34L, 4L, 32L,
17L, 33L, 34L, 33L, 32L, 28L, 31L, 17L, 17L, 4L, 28L, 31L, 4L,
4L, 31L, 32L, 31L, 33L, 31L, 33L, 44L, 45L, 45L), .Label = c("Alameda",
"Butte", "Calaveras", "Contra Costa", "El Dorado", "Fresno",
"Glenn", "Humboldt", "Imperial", "Inyo", "Kern", "Kings", "Lake",
"Lassen", "Los Angeles", "Madera", "Marin", "Mendocino", "Merced",
"Monterey", "Nevada", "Orange", "Placer", "Riverside", "Sacramento",
"San Benito", "San Bernardino", "San Diego", "San Joaquin", "San Luis Obispo",
"San Mateo", "Santa Barbara", "Santa Clara", "Santa Cruz", "Shasta",
"Siskiyou", "Sonoma", "Stanislaus", "Sutter", "Tehama", "Trinity",
"Tulare", "Tuolumne", "Ventura", "Yuba"), class = "factor"),
testscr = c(690.8, 661.2, 643.6, 647.7, 640.85, 605.55, 606.75,
609, 612.5, 612.65, 615.75, 616.3, 616.3, 616.3, 616.45,
617.35, 618.05, 618.3, 619.8, 620.3, 620.5, 621.4, 621.75,
622.05, 622.6, 623.1, 623.2, 623.45, 623.6, 624.15, 624.55,
624.95, 625.3, 625.85, 626.1, 626.8, 626.9, 627.1, 627.25,
627.3, 628.25, 628.4, 628.55, 628.65, 628.75, 629.8, 630.35,
630.4, 630.55, 630.55, 631.05, 631.4, 631.85, 631.9, 631.95,
632, 632.2, 632.25, 632.45, 632.85, 632.95, 633.05, 633.15,
633.65, 633.9, 634, 634.05, 634.1, 634.1, 634.15, 634.2,
634.4, 634.55, 634.7, 634.9, 634.95, 635.05, 635.2, 635.45,
635.6, 635.6, 635.75, 635.95, 636.1, 636.5, 636.6, 636.7,
636.9, 636.95, 637, 637.1, 637.35, 637.65, 637.95, 637.95,
638, 638.2, 638.3, 638.3, 638.35, 638.55, 638.7, 639.25,
639.3, 639.35, 639.5, 639.75, 639.8, 639.85, 639.9, 640.1,
640.15, 640.5, 640.75, 640.9, 641.1, 641.45, 641.45, 641.55,
641.8, 642.2, 642.2, 642.4, 642.75, 643.05, 643.2, 643.25,
643.4, 643.4, 643.5, 643.5, 643.7, 643.7, 644.2, 644.2, 644.4,
644.45, 644.45, 644.5, 644.55, 644.7, 644.95, 645.1, 645.25,
645.55, 645.55, 645.6, 645.75, 645.75, 646, 646.2, 646.35,
646.4, 646.5, 646.55, 646.7, 646.9, 646.95, 647.05, 647.25,
647.3, 647.6, 647.6, 648, 648.2, 648.25, 648.35, 648.7, 648.95,
649.15, 649.3, 649.5, 649.7, 649.85, 650.45, 650.55, 650.6,
650.65, 650.9, 650.9, 651.15, 651.2, 651.35, 651.4, 651.45,
651.8, 651.85, 651.9, 652, 652.1, 652.1, 652.3, 652.3, 652.35,
652.4, 652.4, 652.5, 652.85, 653.1, 653.4, 653.5, 653.55,
653.55, 653.7, 653.8, 653.85, 653.95, 654.1, 654.2, 654.2,
654.3, 654.6, 654.85, 654.85, 654.9, 655.05, 655.05, 655.05,
655.2, 655.3, 655.35, 655.35, 655.4, 655.55, 655.7, 655.8,
655.85, 656.4, 656.5, 656.55, 656.65, 656.7, 656.8, 656.8,
657, 657, 657.15, 657.4, 657.5, 657.55, 657.65, 657.75, 657.8,
657.9, 658, 658.35, 658.6, 658.8, 659.05, 659.15, 659.35,
659.4, 659.4, 659.8, 659.9, 660.05, 660.1, 660.2, 660.3,
660.75, 660.95, 661.35, 661.45, 661.6, 661.6, 661.85, 661.85,
661.85, 661.9, 661.9, 661.95, 662.4, 662.4, 662.45, 662.5,
662.55, 662.55, 662.65, 662.7, 662.75, 662.9, 663.35, 663.45,
663.5, 663.85, 663.85, 663.9, 664, 664, 664.15, 664.15, 664.3,
664.4, 664.45, 664.7, 664.75, 664.95, 664.95, 665.1, 665.2,
665.35, 665.65, 665.9, 665.95, 666, 666.05, 666.1, 666.15,
666.15, 666.45, 666.55, 666.6, 666.65, 666.65, 666.7, 666.85,
666.85, 667.15, 667.2, 667.45, 667.45, 667.6, 668, 668.1,
668.4, 668.6, 668.65, 668.8, 668.9, 668.95, 669.1, 669.3,
669.3, 669.35, 669.35, 669.8, 669.85, 669.95, 670, 670.7,
671.25, 671.3, 671.6, 671.6, 671.65, 671.7, 671.75, 671.9,
671.9, 671.95, 672.05, 672.05, 672.3, 672.35, 672.45, 672.55,
672.7, 673.05, 673.25, 673.3, 673.55, 673.55, 673.9, 674.25,
675.4, 675.7, 676.15, 676.55, 676.6, 676.85, 676.95, 677.25,
677.95, 678.05, 678.4, 678.8, 679.4, 679.5, 679.65, 679.75,
679.8, 680.05, 680.45, 681.3, 681.3, 681.6, 681.9, 682.15,
682.45, 682.55, 682.65, 683.35, 683.4, 684.3, 684.35, 684.8,
684.95, 686.05, 686.7, 687.55, 689.1, 691.05, 691.35, 691.9,
693.95, 694.25, 694.8, 695.2, 695.3, 696.55, 698.2, 698.25,
698.45, 699.1, 700.3, 704.3, 706.75, 645, 672.2, 655.75),
str = c(17.88991, 21.52466, 18.69723, 17.35714, 18.67133,
21.40625, 19.5, 20.89412, 19.94737, 20.80556, 21.23809, 21,
20.6, 20.00822, 18.02778, 20.25196, 16.97787, 16.5098, 22.70402,
19.91111, 18.33333, 22.61905, 19.44828, 25.05263, 20.67544,
18.68235, 22.84553, 19.26667, 19.25, 20.54545, 20.60697,
21.07268, 21.53581, 19.904, 21.19407, 21.86535, 18.32965,
16.22857, 19.17857, 20.27737, 22.98614, 20.44444, 19.82085,
23.20522, 19.26697, 23.30189, 21.18829, 20.8718, 19.01749,
21.91938, 20.10124, 21.47651, 20.06579, 20.3751, 22.44648,
22.89524, 20.49797, 20, 22.25658, 21.56436, 19.47737, 17.67002,
21.94756, 21.78339, 19.14, 18.1105, 20.68242, 22.62361, 21.7865,
18.58293, 21.54545, 21.15289, 16.63333, 21.14438, 19.78182,
18.98373, 17.66767, 17.75499, 15.27273, 14, 20.59613, 16.31169,
21.12796, 17.48801, 17.88679, 19.30676, 20.89231, 21.28684,
20.1956, 24.95, 18.13043, 20, 18.72951, 18.25, 18.99257,
19.88764, 19.37895, 20.46259, 22.29157, 20.70474, 19.06005,
20.23247, 19.69012, 20.36254, 19.75422, 19.37977, 22.92351,
19.3734, 19.15516, 21.3, 18.30357, 21.07926, 18.79121, 19.62662,
19.59016, 20.87187, 21.115, 20.08452, 19.91049, 17.81285,
18.13333, 19.22221, 18.66072, 19.6, 19.28384, 22.81818, 18.80922,
21.37363, 20.02041, 21.49862, 15.42857, 22.4, 20.12709, 19.03798,
17.34216, 17.01863, 20.8, 21.15385, 18.45833, 19.14082, 19.40766,
19.56896, 21.5012, 17.52941, 16.43017, 19.79654, 17.18613,
17.61589, 20.12537, 22.16667, 19.96154, 19.03945, 15.22436,
21.14475, 19.6439, 21.04869, 20.17544, 21.3913, 20.00833,
20.29137, 17.66667, 18.22055, 20.271, 20.19895, 21.38424,
20.97368, 20, 17.15328, 22.34977, 22.17007, 18.18182, 18.95714,
19.74533, 16.42623, 16.6254, 16.38177, 20.07416, 17.99544,
19.3913, 16.42857, 16.72949, 24.41345, 18.26415, 18.95504,
21.03896, 20.74074, 18.1, 19.84615, 21.6, 22.44242, 23.01438,
17.74892, 18.28664, 19.26544, 22.66667, 19.29412, 17.36364,
19.82143, 20.43378, 21.03721, 19.92462, 19.00986, 23.82222,
19.36909, 19.82857, 15.25885, 17.16129, 21.81333, 19.07471,
25.78512, 18.21261, 18.16606, 16.97297, 21.50087, 20.6, 16.99029,
20.77954, 15.51247, 19.88506, 21.39882, 20.49751, 19.36376,
17.65957, 21.01796, 19.05565, 22.53846, 21.10787, 20.05135,
14.20176, 18.47687, 18.63542, 20.94595, 21.08548, 18.69288,
20.86808, 19.82558, 19.75, 19.5, 18.3908, 18.78676, 19.77018,
19.33333, 21.46392, 23.08492, 21.06299, 18.68687, 20.77024,
19.30556, 20.1328, 20.66964, 22.28155, 20.60027, 20.82734,
19.22492, 17.65477, 17, 16.49773, 19.78261, 22.30216, 17.73077,
20.44836, 20.37169, 20.16479, 21.61538, 20.56143, 19.95551,
21.18387, 18.81042, 20.57838, 18.32461, 18.82063, 20.81633,
20, 19.68182, 19.39018, 20.92732, 19.94437, 20.79109, 19.20354,
19.02439, 17.62058, 20.23715, 19.29374, 18.82998, 20.33949,
19.229, 17.8913, 19.51881, 19.08451, 19.93548, 18.87326,
20.14178, 23.55637, 21.46479, 19.19101, 20.1308, 25.8, 18.77774,
19.10982, 19.70109, 18.61594, 20.99721, 20, 20.98325, 21.64262,
20.02967, 19.8114, 18, 19.35811, 20.17912, 21.11986, 23.38974,
22.18182, 19.94283, 17.78826, 14.70588, 19.04077, 20.89195,
19.83851, 19.52191, 20.68622, 18.18182, 18.89224, 24.88889,
18.58064, 18.04, 17.73399, 21.45455, 19.92343, 20.33942,
22.54608, 21.10344, 18.19743, 20.10768, 19.15984, 19.54545,
20.88889, 18.3915, 19.1799, 19.39771, 21.67827, 19.28889,
20.34927, 20.96416, 19.46039, 19.28572, 20.91979, 20.90021,
20.59575, 19.375, 19.95122, 18.84973, 18.11787, 19.18341,
22, 21.58416, 20.38889, 16.2931, 18.27778, 19.37472, 18.90909,
16.40693, 15.5914, 18.70694, 18.32985, 17.90235, 18.91157,
20.32497, 20.02457, 24, 17.60784, 19.34853, 19.67846, 18.72861,
15.88235, 20.05491, 17.98825, 16.96629, 19.23937, 19.19586,
19.59906, 20.54348, 18.58848, 15.60419, 15.29304, 17.65537,
17.57976, 22.33333, 18.75, 18.10241, 20.25641, 18.80207,
18.7723, 20.40521, 18.65079, 20.70707, 22, 17.69978, 21.48329,
16.70103, 19.57567, 17.25806, 17.37526, 17.34931, 16.26229,
17.70045, 20.12881, 18.26539, 14.54214, 19.15261, 17.36574,
15.13898, 17.84266, 15.40704, 18.86534, 16.47413, 17.86263,
21.88586, 20.2, 19.0364)), class = "data.frame", row.names = c(NA,
-420L))

First order of business is to not use $ in aes calls.
Second, create a variable in the data the hold the 3 factor levels you want, and all other levels collapsed into an "other" level, which you'll use to assign color. The easiest way to do that is with forcats::fct_other, where you specify the levels to keep.
You can assign specific colors by name; for a quick example, I didn't, and just put the "other" color last, knowing that fct_other puts this as the last level.
library(ggplot2)
library(dplyr)
hilite_counties <- as_tibble(sample) %>%
mutate(county2 = forcats::fct_other(county, keep = c("Butte", "Los Angeles", "Fresno")))
ggplot(hilite_counties, aes(x = str, y = testscr)) +
geom_point(aes(color = county2)) +
geom_smooth(method = lm) +
scale_color_manual(values = c("red", "blue", "orange", "black"))
Edit: Taking a second pass to make the color palette more flexible. Like I said, you can assign names to colors to make sure you match the county to the color. I'll put black as the last color because "Other" is the last level, but I could assign them in any order and keep the colors and counties matched by name.
Instead of manually naming colors, I'll add another county to the highlighted group, pull a palette from Color Brewer with the length of the county2 levels minus 1, and tack on "black" as the last color, then assign names. Again, I could do this out of order as well.
hilite_counties <- as_tibble(sample) %>%
mutate(county2 = forcats::fct_other(county, keep = c("Butte", "Los Angeles", "Fresno", "Sacramento")))
county_lvls <- levels(hilite_counties$county2)
pal <- c(RColorBrewer::brewer.pal(n = length(county_lvls) - 1, name = "Dark2"), "black")
names(pal) <- county_lvls
pal
#> Butte Fresno Los Angeles Sacramento Other
#> "#1B9E77" "#D95F02" "#7570B3" "#E7298A" "black"
ggplot(hilite_counties, aes(x = str, y = testscr)) +
geom_point(aes(color = county2)) +
geom_smooth(method = lm) +
scale_color_manual(values = pal)
One note: by default, geom_smooth will make lines for each group i.e. color. I'm guessing that's not what you wanted, but you can avoid that by moving the color assignment to a separate aes that only applies to geom_point.

After doing :
p = ggplot(data=sample,aes(x=str, y=testscr))+
geom_point()+
geom_smooth(method="lm")
You could use dplyr library to show in red points of interest :
p + geom_point(data=filter(sample,county %in% c('Butte','Los Angeles','Fresno')),aes(x=str,y=testscr),colour='red')
Or you can add a column indicating if you want to highlight specific points :
sample$code = ifelse(sample$county %in% c('Butte','Los Angeles','Fresno'), TRUE, FALSE)
ggplot(data=sample,aes(x=str,y=testscr))+
geom_point(aes(colour=code),sample)+
geom_smooth(method="lm") +
scale_colour_manual(name = 'County', values = c("black", "red"), labels = c('Others', 'B, LA, F'))
[edit]
Or with one color by city :
city = c('Butte','Los Angeles','Fresno')
sample %>% mutate_if(is.factor, as.character) -> sample
sample$code = ifelse(sample$county %in% city, sample$county, 'others')
ggplot(data=sample,aes(x=str,y=testscr))+
geom_point(aes(colour=code),sample)+
geom_smooth(method="lm") +
scale_colour_manual(name = 'County', values = c("blue", "red","green","black"))

Another option would be to create two separate layers, one for the special counties and another for the rest. You can do that by subsetting the default dataset in the specification of each layer.
special_county <- c("Butte", "Los Angeles", "Fresno")
ggplot(data=sample, aes(x=str,y=testscr))+
geom_smooth(method="lm") +
geom_point(data = function(x) subset(x, !county %in% special_county)) +
geom_point(data = function(x) subset(x, county %in% special_county),
aes(color = county))
For completeness sake, you can also get the result you want by using scale_color_manual to specify the color for each of the 45 counties, but I guess that wouldn't be very elegant.

Related

Is there a way to reorder tip labels of a phylo object so that they are consistent with another phylo object?

I have two trees that I am trying to compare. One from mrbayes, another from Paup.
When I use read.nexus, the resulting phylo objects have differently ordered tip labels, despite the fact that both files have the same nexus taxa block.
I've reproduced these trees below:
library(ape)
#trees
t1 <- structure(list(edge = structure(c(29L, 30L, 30L, 30L, 30L, 31L,
31L, 32L, 32L, 33L, 34L, 35L, 35L, 35L, 34L, 36L, 37L, 38L, 38L,
38L, 38L, 37L, 39L, 40L, 40L, 39L, 39L, 39L, 39L, 36L, 36L, 36L,
36L, 33L, 31L, 31L, 31L, 31L, 29L, 30L, 1L, 2L, 3L, 31L, 4L,
32L, 5L, 33L, 34L, 35L, 6L, 7L, 8L, 36L, 37L, 38L, 9L, 10L, 11L,
12L, 39L, 40L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L), .Dim = c(39L, 2L)), Nnode = 12L,
tip.label = c("Metaspriggina", "Eptatretus", "Mordacia",
"Lasanius", "Phlebolepis", "Zenaspis", "Diademaspis", "Ukrainaspis",
"Tamiobatis", "Ischnacanthus", "Mesacanthus", "Tetanopsyrus",
"Mimipiscis", "Raynerius", "Diabolepis", "Guiyu", "Gavinia",
"Qingmenodus", "Kujdanowiaspis", "Cowralepis", "Jagorina",
"Macropetalichthys", "Polybranchiaspis", "Cyathaspis", "Irregulareaspis",
"Listraspis", "Unarkaspis", "Pikaia")), class = "phylo", order = "cladewise")
t2 <- structure(list(edge = structure(c(29L, 29L, 30L, 30L, 31L, 32L,
33L, 33L, 32L, 31L, 31L, 31L, 31L, 31L, 31L, 34L, 35L, 36L, 37L,
37L, 36L, 35L, 38L, 39L, 40L, 41L, 42L, 42L, 42L, 42L, 41L, 43L,
44L, 44L, 43L, 45L, 46L, 47L, 47L, 46L, 45L, 40L, 48L, 48L, 39L,
38L, 34L, 1L, 30L, 2L, 31L, 32L, 33L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 34L, 35L, 36L, 37L, 11L, 12L, 13L, 38L, 39L, 40L, 41L,
42L, 21L, 23L, 24L, 17L, 43L, 44L, 22L, 27L, 45L, 46L, 47L, 28L,
26L, 25L, 16L, 48L, 15L, 19L, 18L, 20L, 14L), .Dim = c(47L, 2L
)), Nnode = 20L, tip.label = c("Pikaia", "Metaspriggina", "Eptatretus",
"Mordacia", "Lasanius", "Phlebolepis", "Cyathaspis", "Irregulareaspis",
"Listraspis", "Unarkaspis", "Zenaspis", "Diademaspis", "Ukrainaspis",
"Polybranchiaspis", "Cowralepis", "Guiyu", "Ischnacanthus", "Jagorina",
"Kujdanowiaspis", "Macropetalichthys", "Mesacanthus", "Mimipiscis",
"Tamiobatis", "Tetanopsyrus", "Diabolepis", "Gavinia", "Raynerius",
"Qingmenodus")), class = "phylo", order = "cladewise")
#tip labels are the same
all.equal(sort(t1$tip.label), sort(t2$tip.label))
#[1] TRUE
#tip label order is different
all.equal(t1$tip.label, t2$tip.label)
#[1] "26 string mismatches"
Is there a way to reorder the tip labels of t1, so they are consistent with t2?
The solution depends very much on what you want to do with the trees. Most phylogenetic comparative methods use identical names in trees and correctly assign them. A simple match for the two trees can be found as:
match(match(t1$tip.label, t2$tip.label)
# [1] 2 3 4 5 6 11 12 13 23 17 21 24 22 27 25 16 26 28 19 15 18 20 14 7 8 9 10 1
To reorder the tree, you can use ladderize(t1), but that will only influence the plotting, not the tip label order. A nice, easy trick how to re-number the nodes and keep the tip labels in the ladderized display is to save the tree and load it again.
write.tree(ladderize(t1), file = "t1.tre")
t1 = read.tree("t1.tre")
However, your trees have different topologies, so matching the tip labels must be done with respect to the downstream analyses.
cophyloplot(ladderize(t1), ladderize(t2),
assoc = matrix(rep(t1$tip.label, 2), ncol = 2))
I think this is what you are after:
trees <- c(t1, t2)
trees <- .compressTipLabel(trees)
t2 <- trees[[2]]
all.equal(t1$tip.label, t2$tip.label)

Convert quarter character into date object in R

I have a dataset and a column in there with information on the "period" of the observations which is a character for quarters of year. The column looks like this:
> dput(df$Period)
structure(c(27L, 40L, 1L, 3L, 15L, 42L, 29L, 35L, 21L, 48L, 9L,
41L, 28L, 2L, 14L, 45L, 32L, 18L, 6L, 22L, 49L, 36L, 10L, 27L,
1L, 40L, 2L, 41L, 14L, 28L, 15L, 3L, 42L, 29L, 6L, 32L, 45L,
18L, 48L, 21L, 35L, 9L, 10L, 49L, 22L, 36L, 2L, 41L, 28L, 14L,
45L, 6L, 18L, 32L, 10L, 49L, 22L, 36L, 18L, 6L, 45L, 32L, 49L,
36L, 22L, 10L, 14L, 2L, 41L, 28L, 45L, 18L, 32L, 6L, 49L, 10L,
22L, 36L, 32L, 18L, 45L, 6L, 36L, 10L, 22L, 49L, 14L, 41L, 28L,
2L, 27L, 40L, 1L, 35L, 9L, 48L, 21L, 27L, 40L, 1L, 35L, 21L,
48L, 9L, 1L, 40L, 27L, 41L, 28L, 2L, 14L, 42L, 15L, 3L, 29L,
32L, 45L, 6L, 18L, 48L, 9L, 21L, 35L, 10L, 49L, 36L, 22L, 1L,
40L, 27L, 14L, 28L, 41L, 2L, 29L, 15L, 42L, 3L, 18L, 6L, 32L,
45L, 49L, 36L, 22L, 10L, 27L, 1L, 40L, 2L, 41L, 28L, 14L, 15L,
42L, 29L, 3L, 6L, 45L, 18L, 32L, 7L, 19L, 46L, 33L, 9L, 35L,
21L, 48L, 10L, 22L, 49L, 36L, 1L, 40L, 27L, 2L, 14L, 28L, 41L,
3L, 42L, 15L, 29L, 18L, 32L, 45L, 6L, 46L, 33L, 19L, 7L, 35L,
9L, 21L, 48L, 49L, 22L, 36L, 10L, 1L, 27L, 40L, 29L, 15L, 3L,
42L, 45L, 6L, 18L, 32L, 9L, 21L, 35L, 48L, 36L, 49L, 10L, 22L,
2L, 28L, 14L, 41L, 32L, 18L, 45L, 6L, 36L, 49L, 22L, 10L, 1L,
27L, 40L, 43L, 30L, 16L, 4L, 44L, 31L, 17L, 5L, 32L, 18L, 45L,
6L, 49L, 36L, 22L, 10L, 27L, 40L, 1L, 9L, 35L, 21L, 48L, 27L,
1L, 40L, 2L, 41L, 28L, 14L, 42L, 29L, 15L, 3L, 18L, 6L, 32L,
45L, 46L, 7L, 19L, 33L, 48L, 21L, 9L, 35L, 36L, 10L, 22L, 49L,
14L, 28L, 41L, 2L, 32L, 6L, 18L, 45L, 22L, 10L, 49L, 36L, 40L,
1L, 27L, 14L, 41L, 28L, 2L, 42L, 29L, 15L, 3L, 6L, 18L, 45L,
32L, 33L, 19L, 7L, 46L, 9L, 48L, 35L, 21L, 36L, 49L, 10L, 22L,
41L, 28L, 2L, 14L, 18L, 6L, 45L, 32L, 36L, 22L, 49L, 10L, 41L,
2L, 28L, 14L, 45L, 18L, 6L, 32L, 22L, 36L, 49L, 10L, 40L, 27L,
1L, 28L, 41L, 2L, 14L, 3L, 15L, 29L, 42L, 32L, 18L, 6L, 45L,
35L, 21L, 48L, 9L, 36L, 22L, 10L, 49L, 32L, 45L, 6L, 18L, 10L,
22L, 49L, 36L, 41L, 28L, 14L, 2L, 45L, 18L, 6L, 32L, 36L, 49L,
10L, 22L, 28L, 2L, 41L, 14L, 45L, 6L, 32L, 18L, 22L, 36L, 10L,
49L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 42L, 3L, 29L, 15L, 17L,
44L, 31L, 5L, 6L, 32L, 18L, 45L, 9L, 48L, 35L, 21L, 36L, 22L,
10L, 49L, 2L, 14L, 41L, 28L, 32L, 18L, 45L, 6L, 49L, 22L, 10L,
36L, 41L, 28L, 14L, 2L, 6L, 45L, 32L, 18L, 22L, 10L, 49L, 36L,
40L, 1L, 27L, 35L, 21L, 9L, 48L, 1L, 40L, 27L, 14L, 2L, 28L,
41L, 29L, 3L, 15L, 42L, 6L, 45L, 32L, 18L, 46L, 7L, 33L, 19L,
21L, 9L, 35L, 48L, 36L, 10L, 22L, 49L, 28L, 41L, 2L, 14L, 18L,
6L, 45L, 32L, 36L, 22L, 49L, 10L, 1L, 40L, 27L, 28L, 14L, 41L,
2L, 16L, 30L, 43L, 4L, 45L, 6L, 32L, 18L, 20L, 8L, 47L, 34L,
9L, 35L, 48L, 21L, 22L, 36L, 49L, 10L, 41L, 2L, 28L, 14L, 18L,
32L, 45L, 6L, 49L, 22L, 10L, 36L, 27L, 1L, 40L, 48L, 35L, 9L,
21L, 14L, 2L, 41L, 28L, 6L, 45L, 18L, 32L, 36L, 49L, 10L, 22L,
40L, 1L, 27L, 41L, 2L, 28L, 14L, 42L, 3L, 15L, 29L, 17L, 31L,
44L, 5L, 32L, 18L, 45L, 6L, 46L, 33L, 19L, 7L, 9L, 35L, 21L,
48L, 36L, 49L, 10L, 22L, 6L, 18L, 32L, 45L, 10L, 49L, 22L, 36L,
1L, 27L, 40L, 2L, 41L, 28L, 14L, 42L, 29L, 15L, 3L, 18L, 32L,
45L, 6L, 46L, 7L, 33L, 19L, 48L, 21L, 9L, 35L, 49L, 10L, 22L,
36L, 27L, 1L, 40L, 2L, 28L, 14L, 41L, 15L, 3L, 42L, 29L, 45L,
32L, 6L, 18L, 9L, 35L, 48L, 21L, 10L, 36L, 49L, 22L, 40L, 1L,
27L, 41L, 28L, 14L, 2L, 42L, 15L, 29L, 3L, 32L, 6L, 45L, 18L,
46L, 19L, 33L, 7L, 35L, 9L, 21L, 48L, 10L, 22L, 36L, 49L, 27L,
1L, 40L, 41L, 14L, 2L, 28L, 29L, 3L, 15L, 42L, 44L, 31L, 17L,
5L, 6L, 18L, 32L, 45L, 7L, 46L, 33L, 19L, 21L, 35L, 9L, 48L,
22L, 49L, 36L, 10L, 1L, 40L, 27L, 35L, 48L, 9L, 21L, 27L, 1L,
40L, 2L, 28L, 41L, 14L, 42L, 29L, 3L, 15L, 18L, 6L, 32L, 45L,
7L, 33L, 46L, 19L, 9L, 21L, 35L, 48L, 36L, 22L, 10L, 49L, 41L,
2L, 14L, 28L, 18L, 6L, 45L, 32L, 10L, 22L, 49L, 36L, 1L, 40L,
27L, 28L, 14L, 41L, 2L, 42L, 29L, 3L, 15L, 18L, 32L, 45L, 6L,
7L, 33L, 19L, 46L, 35L, 48L, 9L, 21L, 49L, 36L, 22L, 10L, 40L,
1L, 27L, 41L, 2L, 14L, 28L, 15L, 3L, 29L, 42L, 45L, 32L, 6L,
18L, 19L, 7L, 33L, 46L, 21L, 48L, 9L, 35L, 36L, 22L, 49L, 10L,
4L, 30L, 43L, 18L, 45L, 32L, 6L, 10L, 36L, 49L, 22L, 28L, 2L,
41L, 14L, 45L, 32L, 6L, 18L, 22L, 36L, 49L, 10L, 41L, 28L, 2L,
14L, 45L, 6L, 32L, 18L, 22L, 36L, 49L, 10L, 27L, 1L, 40L, 3L,
15L, 29L, 42L, 46L, 7L, 33L, 19L, 9L, 35L, 21L, 48L, 27L, 40L,
1L, 2L, 14L, 41L, 28L, 15L, 3L, 42L, 29L, 32L, 6L, 18L, 45L,
7L, 19L, 33L, 46L, 35L, 9L, 21L, 48L, 36L, 49L, 22L, 10L, 6L,
45L, 18L, 32L, 22L, 36L, 49L, 10L, 45L, 32L, 18L, 6L, 10L, 22L,
49L, 36L, 27L, 40L, 1L, 41L, 28L, 2L, 14L, 45L, 6L, 18L, 32L,
36L, 49L, 10L, 22L, 14L, 41L, 28L, 2L, 18L, 32L, 45L, 6L, 49L,
10L, 22L, 36L, 6L, 45L, 32L, 18L, 22L, 27L, 1L, 40L, 2L, 41L,
28L, 14L, 3L, 42L, 15L, 29L, 45L, 6L, 32L, 18L, 46L, 7L, 19L,
33L, 48L, 35L, 21L, 9L, 49L, 10L, 22L, 36L, 31L, 17L, 44L, 5L,
18L, 40L, 1L, 27L, 2L, 14L, 41L, 28L, 42L, 3L, 29L, 15L, 18L,
6L, 45L, 32L, 19L, 7L, 46L, 33L, 21L, 35L, 48L, 9L, 22L, 10L,
49L, 36L, 1L, 27L, 40L, 41L, 2L, 28L, 14L, 6L, 32L, 45L, 18L,
10L, 22L, 36L, 49L, 32L, 18L, 45L, 6L, 49L, 22L, 36L, 10L, 43L,
4L, 30L, 41L, 14L, 2L, 28L, 6L, 32L, 18L, 45L, 22L, 10L, 36L,
49L, 27L, 1L, 40L, 42L, 15L, 29L, 3L, 31L, 5L, 44L, 17L, 45L,
6L, 32L, 18L, 35L, 9L, 21L, 48L, 49L, 36L, 10L, 22L, 1L, 40L,
27L, 28L, 14L, 2L, 41L, 42L, 15L, 3L, 29L, 6L, 32L, 45L, 18L,
9L, 35L, 48L, 21L, 10L, 36L, 22L, 49L, 40L, 27L, 1L, 27L, 1L,
40L, 48L, 21L, 35L, 9L, 41L, 2L, 14L, 28L, 18L, 45L, 32L, 6L,
10L, 22L, 36L, 49L, 41L, 28L, 2L, 14L, 18L, 45L, 32L, 6L, 22L,
49L, 36L, 10L, 14L, 41L, 2L, 28L, 6L, 32L, 18L, 45L, 22L, 10L,
49L, 36L, 1L, 27L, 40L, 42L, 29L, 3L, 15L, 18L, 32L, 6L, 45L,
19L, 46L, 7L, 33L, 9L, 35L, 48L, 21L, 22L, 10L, 36L, 49L, 1L,
27L, 40L, 28L, 2L, 41L, 14L, 3L, 42L, 15L, 29L, 17L, 44L, 31L,
5L, 45L, 18L, 6L, 32L, 46L, 7L, 33L, 19L, 35L, 21L, 9L, 48L,
10L, 36L, 49L, 22L, 2L, 41L, 28L, 14L, 45L, 32L, 6L, 18L, 49L,
10L, 22L, 36L, 40L, 27L, 1L, 2L, 41L, 28L, 14L, 29L, 42L, 3L,
15L, 45L, 32L, 18L, 6L, 48L, 9L, 35L, 21L, 49L, 10L, 22L, 36L,
14L, 28L, 2L, 41L, 18L, 45L, 32L, 6L, 49L, 10L, 36L, 22L, 27L,
40L, 1L, 41L, 14L, 2L, 28L, 29L, 15L, 3L, 42L, 32L, 6L, 18L,
45L, 9L, 35L, 21L, 48L, 10L, 22L, 36L, 49L, 3L, 15L, 42L, 29L,
40L, 27L, 1L, 48L, 35L, 9L, 21L, 14L, 2L, 41L, 28L, 45L, 32L,
6L, 18L, 49L, 10L, 36L, 22L, 18L, 45L, 32L, 6L, 36L, 22L, 49L,
10L, 18L, 2L, 41L, 28L, 14L, 32L, 45L, 18L, 6L, 36L, 49L, 22L,
10L, 2L, 28L, 14L, 41L, 32L, 6L, 18L, 45L, 22L, 36L, 49L, 10L,
45L, 18L, 32L, 6L, 10L, 36L, 49L, 22L, 32L, 18L, 6L, 45L, 49L,
10L, 22L, 36L, 41L, 14L, 28L, 2L, 18L, 6L, 45L, 32L, 36L, 22L,
10L, 49L, 40L, 27L, 1L, 45L, 32L, 18L, 6L, 49L, 10L, 36L, 22L,
40L, 27L, 1L, 2L, 41L, 28L, 14L, 29L, 3L, 42L, 15L, 18L, 6L,
45L, 32L, 33L, 19L, 46L, 7L, 21L, 9L, 48L, 35L, 49L, 10L, 36L,
22L, 28L, 2L, 41L, 14L, 17L, 44L, 31L, 5L, 18L, 32L, 45L, 6L,
10L, 49L, 36L, 22L, 27L, 40L, 1L, 27L, 1L, 40L, 41L, 28L, 14L,
2L, 42L, 15L, 29L, 3L, 5L, 17L, 31L, 44L, 45L, 32L, 6L, 18L,
46L, 7L, 33L, 19L, 48L, 9L, 21L, 35L, 49L, 10L, 36L, 27L, 1L,
40L, 48L, 9L, 21L, 35L, 40L, 1L, 27L, 2L, 28L, 14L, 41L, 42L,
3L, 29L, 15L, 6L, 32L, 45L, 18L, 46L, 33L, 19L, 7L, 48L, 9L,
21L, 35L, 10L, 22L, 36L, 49L, 2L, 14L, 28L, 41L, 45L, 6L, 32L,
18L, 10L, 49L, 22L, 36L, 14L, 41L, 2L, 28L, 18L, 45L, 6L, 32L,
10L, 49L, 22L, 36L, 40L, 1L, 27L, 42L, 15L, 3L, 29L, 45L, 18L,
6L, 32L, 7L, 33L, 19L, 46L, 21L, 9L, 48L, 35L, 36L, 10L, 22L,
49L, 40L, 1L, 27L, 3L, 29L, 15L, 42L, 46L, 19L, 33L, 7L, 48L,
21L, 9L, 35L, 41L, 14L, 28L, 2L, 32L, 18L, 6L, 45L, 49L, 36L,
22L, 10L, 28L, 2L, 41L, 14L, 6L, 32L, 45L, 18L, 36L, 10L, 22L,
49L, 41L, 2L, 28L, 14L, 32L, 18L, 45L, 6L, 36L, 22L, 49L, 10L,
14L, 28L, 2L, 41L, 32L, 45L, 18L, 6L, 10L, 36L, 22L, 49L, 27L,
40L, 1L, 28L, 41L, 14L, 2L, 42L, 29L, 15L, 3L, 6L, 45L, 18L,
32L, 9L, 35L, 48L, 21L, 22L, 10L, 36L, 49L, 18L, 6L, 45L, 32L,
22L, 10L, 49L, 36L, 27L, 1L, 40L, 28L, 14L, 41L, 2L, 29L, 42L,
15L, 3L, 6L, 45L, 32L, 18L, 33L, 46L, 19L, 7L, 21L, 48L, 9L,
35L, 36L, 49L, 10L, 22L, 27L, 40L, 1L, 42L, 15L, 3L, 29L, 46L,
19L, 7L, 33L, 9L, 35L, 48L, 21L, 28L, 41L, 2L, 14L, 45L, 6L,
32L, 18L, 10L, 36L, 22L, 49L, 1L, 27L, 40L, 14L, 2L, 28L, 41L,
15L, 3L, 29L, 42L, 18L, 32L, 45L, 6L, 7L, 33L, 46L, 19L, 48L,
35L, 9L, 21L, 49L, 10L, 22L, 36L, 40L, 1L, 27L, 48L, 35L, 21L,
9L, 14L, 28L, 41L, 2L, 6L, 45L, 18L, 32L, 49L, 36L, 10L, 22L,
40L, 27L, 1L, 48L, 21L, 9L, 35L, 27L, 40L, 1L, 28L, 14L, 2L,
41L, 42L, 29L, 15L, 3L, 32L, 45L, 18L, 6L, 21L, 9L, 48L, 35L,
36L, 49L, 10L, 22L, 6L, 32L, 18L, 45L, 49L, 22L, 36L, 10L, 27L,
1L, 40L, 48L, 35L, 21L, 9L, 28L, 14L, 41L, 2L, 32L, 18L, 45L,
6L, 22L, 36L, 10L, 49L, 1L, 40L, 27L, 35L, 48L, 9L, 21L, 1L,
27L, 40L, 14L, 28L, 2L, 41L, 15L, 42L, 3L, 29L, 6L, 45L, 32L,
18L, 19L, 33L, 46L, 7L, 48L, 9L, 21L, 35L, 10L, 22L, 36L, 49L,
40L, 1L, 27L, 3L, 29L, 15L, 42L, 6L, 18L, 45L, 32L, 7L, 19L,
33L, 46L, 35L, 21L, 48L, 9L, 10L, 22L, 49L, 36L, 40L, 1L, 27L,
21L, 35L, 9L, 48L, 1L, 40L, 27L, 14L, 2L, 41L, 28L, 15L, 29L,
3L, 42L, 44L, 31L, 5L, 17L, 45L, 18L, 6L, 32L, 46L, 33L, 7L,
19L, 9L, 21L, 48L, 35L, 36L, 22L, 49L, 10L, 40L, 1L, 27L, 41L,
2L, 28L, 14L, 3L, 29L, 42L, 15L, 6L, 32L, 18L, 45L, 7L, 19L,
33L, 46L, 21L, 9L, 48L, 35L, 22L, 10L, 36L, 49L, 40L, 1L, 27L,
42L, 29L, 15L, 3L, 46L, 33L, 19L, 7L, 35L, 9L, 21L, 48L, 27L,
40L, 1L, 41L, 14L, 28L, 2L, 42L, 15L, 3L, 29L, 32L, 6L, 45L,
18L, 7L, 46L, 33L, 19L, 21L, 9L, 48L, 35L, 49L, 10L, 36L, 22L,
27L, 40L, 1L, 9L, 35L, 21L, 48L, 2L, 41L, 14L, 28L, 6L, 45L,
18L, 32L, 36L, 10L, 49L, 22L, 40L, 27L, 1L, 14L, 41L, 28L, 2L,
29L, 15L, 3L, 42L, 18L, 32L, 6L, 45L, 7L, 33L, 19L, 46L, 21L,
35L, 9L, 48L, 49L, 10L, 36L, 22L, 14L, 2L, 41L, 28L, 45L, 6L,
32L, 18L, 49L, 36L, 22L, 10L, 1L, 27L, 40L, 48L, 35L, 9L, 21L,
18L, 32L, 6L, 45L, 10L, 22L, 36L, 49L, 28L, 2L, 14L, 41L, 6L,
45L, 18L, 32L, 10L, 22L, 49L, 36L, 27L, 40L, 1L, 9L, 35L, 21L,
48L, 1L, 27L, 40L, 41L, 14L, 28L, 2L, 29L, 15L, 42L, 3L, 18L,
32L, 45L, 6L, 19L, 7L, 33L, 46L, 9L, 35L, 21L, 48L, 49L, 22L,
10L, 36L, 27L, 1L, 40L, 14L, 28L, 2L, 41L, 29L, 3L, 42L, 15L,
32L, 6L, 45L, 18L, 33L, 46L, 19L, 7L, 9L, 21L, 35L, 48L, 10L,
22L, 49L, 36L, 40L, 27L, 1L, 2L, 28L, 41L, 14L, 15L, 29L, 42L,
3L, 6L, 32L, 45L, 18L, 21L, 35L, 9L, 48L, 22L, 49L, 36L, 10L,
30L, 43L, 16L, 4L, 30L, 43L, 4L, 16L, 1L, 40L, 27L, 48L, 9L,
35L, 21L, 45L, 32L, 6L, 18L, 10L, 22L, 36L, 49L, 1L, 27L, 40L,
41L, 14L, 2L, 28L, 42L, 15L, 29L, 3L, 45L, 6L, 32L, 18L, 21L,
9L, 48L, 35L, 36L, 10L, 49L, 22L, 27L, 1L, 40L, 28L, 2L, 14L,
41L, 15L, 29L, 3L, 42L, 31L, 44L, 17L, 5L, 6L, 45L, 32L, 18L,
48L, 35L, 9L, 21L, 22L, 10L, 49L, 36L, 40L, 1L, 27L, 9L, 48L,
35L, 21L, 41L, 28L, 2L, 14L, 18L, 6L, 45L, 32L, 49L, 10L, 36L,
22L, 27L, 40L, 1L, 28L, 41L, 14L, 2L, 29L, 3L, 42L, 15L, 45L,
6L, 18L, 32L, 19L, 46L, 7L, 33L, 9L, 21L, 48L, 35L, 36L, 10L,
22L, 49L, 28L, 41L, 14L, 2L, 18L, 32L, 45L, 6L, 22L, 36L, 10L,
49L, 32L, 45L, 18L, 6L, 49L, 10L, 22L, 36L, 27L, 1L, 40L, 35L,
48L, 21L, 9L, 41L, 14L, 2L, 28L, 18L, 45L, 6L, 32L, 49L, 36L,
22L, 10L, 1L, 27L, 40L, 29L, 3L, 15L, 42L, 18L, 32L, 6L, 45L,
46L, 33L, 7L, 19L, 9L, 48L, 35L, 21L, 22L, 10L, 36L, 49L, 27L,
1L, 40L, 2L, 41L, 14L, 28L, 42L, 15L, 3L, 29L, 45L, 18L, 32L,
6L, 19L, 7L, 46L, 33L, 21L, 48L, 9L, 35L, 22L, 10L, 36L, 49L,
2L, 41L, 14L, 28L, 18L, 45L, 32L, 6L, 36L, 49L, 22L, 10L, 27L,
40L, 1L, 40L, 27L, 1L, 14L, 28L, 41L, 2L, 3L, 15L, 42L, 29L,
32L, 6L, 18L, 45L, 46L, 33L, 19L, 7L, 21L, 35L, 9L, 48L, 10L,
36L, 49L, 22L, 41L, 28L, 2L, 14L, 45L, 18L, 6L, 32L, 10L, 36L,
49L, 22L, 41L, 14L, 28L, 2L, 6L, 18L, 32L, 45L, 10L, 22L, 36L,
49L, 1L, 40L, 27L, 14L, 28L, 41L, 2L, 15L, 42L, 3L, 29L, 45L,
32L, 6L, 18L, 7L, 19L, 46L, 33L, 48L, 9L, 21L, 35L, 49L, 22L,
36L, 10L, 45L, 18L, 32L, 6L, 10L, 36L, 22L, 49L, 14L, 28L, 41L,
2L, 18L, 32L, 6L, 45L, 22L, 36L, 10L, 49L, 18L, 32L, 6L, 45L,
10L, 36L, 49L, 22L, 18L, 32L, 6L, 45L, 49L, 36L, 22L, 10L, 27L,
40L, 1L, 9L, 21L, 48L, 35L, 18L, 32L, 45L, 6L, 22L, 10L, 49L,
36L, 28L, 2L, 14L, 41L, 6L, 32L, 45L, 18L, 10L, 49L, 22L, 36L,
2L, 14L, 41L, 28L, 18L, 32L, 6L, 45L, 36L, 10L, 49L, 22L, 2L,
28L, 14L, 41L, 32L, 6L, 18L, 45L, 10L, 49L, 22L, 36L, 40L, 27L,
1L, 14L, 41L, 2L, 28L, 29L, 3L, 15L, 42L, 6L, 45L, 32L, 18L,
46L, 7L, 33L, 19L, 35L, 21L, 9L, 48L, 36L, 10L, 22L, 49L, 40L,
1L, 27L, 41L, 14L, 28L, 2L, 3L, 29L, 42L, 15L, 18L, 32L, 6L,
45L, 7L, 33L, 19L, 46L, 9L, 21L, 48L, 35L, 22L, 10L, 49L, 36L,
2L, 14L, 41L, 28L, 45L, 6L, 18L, 32L, 22L, 49L, 36L, 10L, 45L,
18L, 32L, 6L, 49L, 10L, 36L, 22L, 1L, 27L, 40L, 14L, 41L, 28L,
2L, 15L, 3L, 29L, 42L, 32L, 18L, 45L, 6L, 7L, 46L, 33L, 19L,
48L, 9L, 21L, 35L, 49L, 36L, 10L, 22L, 40L, 1L, 27L, 9L, 35L,
48L, 21L, 45L, 32L, 18L, 6L, 22L, 10L, 36L, 49L, 18L, 2L, 14L,
28L, 41L, 6L, 18L, 32L, 45L, 22L, 49L, 36L, 10L, 27L, 1L, 40L,
41L, 28L, 2L, 14L, 3L, 15L, 42L, 29L, 6L, 32L, 18L, 45L, 7L,
46L, 33L, 19L, 9L, 48L, 35L, 21L, 49L, 36L, 22L, 10L, 40L, 1L,
27L, 14L, 2L, 41L, 28L, 3L, 29L, 15L, 42L, 18L, 6L, 32L, 45L,
33L, 19L, 46L, 7L, 48L, 21L, 9L, 35L, 22L, 36L, 10L, 49L, 45L,
18L, 6L, 32L, 36L, 49L, 22L, 10L, 41L, 14L, 28L, 2L, 6L, 45L,
18L, 32L, 49L, 10L, 22L, 36L, 2L, 14L, 41L, 28L, 45L, 6L, 32L,
18L, 36L, 49L, 10L, 22L, 2L, 14L, 28L, 41L, 45L, 32L, 18L, 6L,
10L, 36L, 49L, 22L, 1L, 27L, 40L, 41L, 2L, 28L, 14L, 42L, 29L,
15L, 3L, 32L, 18L, 45L, 6L, 21L, 35L, 9L, 48L, 36L, 10L, 49L,
22L, 28L, 2L, 41L, 14L, 18L, 32L, 6L, 45L, 49L, 10L, 36L, 22L,
6L, 45L, 18L, 32L, 22L, 49L, 36L, 10L, 45L, 6L, 18L, 32L, 22L,
49L, 36L, 10L, 31L, 5L, 17L, 44L, 1L, 27L, 40L, 28L, 2L, 41L,
14L, 42L, 29L, 15L, 3L, 45L, 18L, 32L, 6L, 46L, 7L, 19L, 33L,
48L, 21L, 35L, 9L, 36L, 10L, 49L, 22L, 14L, 28L, 41L, 2L, 32L,
6L, 18L, 45L, 36L, 10L, 49L, 22L, 1L, 27L, 40L, 42L, 3L, 15L,
29L, 19L, 7L, 46L, 33L, 48L, 21L, 9L, 35L, 6L, 18L, 32L, 45L,
22L, 49L, 36L, 10L, 1L, 27L, 40L, 28L, 14L, 41L, 2L, 42L, 15L,
29L, 3L, 45L, 18L, 32L, 6L, 21L, 9L, 48L, 35L, 10L, 22L, 36L,
49L, 1L, 40L, 27L, 29L, 15L, 42L, 3L, 19L, 7L, 33L, 46L, 48L,
35L, 9L, 21L, 27L, 1L, 40L, 14L, 2L, 41L, 28L, 15L, 29L, 3L,
42L, 18L, 6L, 32L, 45L, 46L, 7L, 19L, 33L, 9L, 35L, 21L, 48L,
22L, 10L, 36L, 49L, 27L, 1L, 40L, 27L, 40L, 1L, 14L, 28L, 41L,
2L, 3L, 29L, 42L, 15L, 32L, 6L, 18L, 45L, 33L, 46L, 19L, 7L,
9L, 21L, 48L, 35L, 22L, 10L, 49L, 36L, 40L, 1L, 27L, 41L, 2L,
14L, 28L, 3L, 15L, 29L, 42L, 18L, 45L, 32L, 6L, 33L, 46L, 7L,
19L, 9L, 35L, 48L, 21L, 22L, 49L, 10L, 36L, 2L, 28L, 14L, 41L,
45L, 32L, 6L, 18L, 10L, 22L, 49L, 36L, 40L, 27L, 1L, 28L, 14L,
2L, 41L, 15L, 3L, 42L, 29L, 45L, 6L, 32L, 18L, 19L, 33L, 7L,
46L, 35L, 48L, 9L, 21L, 10L, 22L, 36L, 49L, 27L, 40L, 1L, 28L,
2L, 41L, 14L, 3L, 29L, 15L, 42L, 31L, 5L, 44L, 17L, 45L, 32L,
18L, 6L, 46L, 33L, 19L, 7L, 21L, 9L, 35L, 48L, 22L, 10L, 36L,
49L, 40L, 27L, 1L, 42L, 15L, 29L, 3L, 18L, 40L, 1L, 27L, 2L,
28L, 14L, 41L, 15L, 3L, 29L, 42L, 32L, 18L, 6L, 45L, 7L, 46L,
19L, 33L, 48L, 9L, 35L, 21L, 22L, 10L, 36L, 49L, 1L, 40L, 27L,
44L, 17L, 5L, 31L, 21L, 9L, 48L, 35L, 41L, 14L, 28L, 2L, 32L,
6L, 18L, 45L, 49L, 22L, 10L, 36L, 40L, 1L, 27L, 2L, 28L, 41L,
14L, 3L, 15L, 29L, 42L, 32L, 18L, 6L, 45L, 46L, 19L, 7L, 33L,
21L, 48L, 9L, 35L, 36L, 22L, 49L, 10L, 1L, 27L, 40L, 41L, 2L,
28L, 14L, 29L, 42L, 3L, 15L, 32L, 45L, 6L, 18L, 33L, 46L, 19L,
7L, 35L, 9L, 48L, 21L, 36L, 10L, 49L, 22L, 14L, 2L, 41L, 28L,
45L, 6L, 18L, 32L, 49L, 10L, 22L, 36L, 1L, 27L, 40L, 48L, 35L,
9L, 21L, 6L, 45L, 32L, 18L, 36L, 10L, 49L, 22L, 40L, 27L, 1L,
41L, 2L, 14L, 28L, 29L, 42L, 3L, 15L, 32L, 6L, 45L, 18L, 19L,
46L, 33L, 7L, 48L, 9L, 21L, 35L, 22L, 10L, 36L, 49L, 40L, 27L,
1L, 41L, 14L, 2L, 28L, 29L, 42L, 15L, 3L, 5L, 31L, 44L, 17L,
45L, 32L, 18L, 6L, 33L, 46L, 19L, 7L, 48L, 21L, 35L, 9L, 49L,
10L, 36L, 22L, 27L, 1L, 40L, 28L, 41L, 2L, 14L, 29L, 15L, 3L,
42L, 6L, 45L, 32L, 18L, 46L, 33L, 19L, 7L, 21L, 35L, 48L, 9L,
22L, 36L, 10L, 49L, 18L, 32L, 6L, 45L, 49L, 10L, 22L, 36L, 27L,
40L, 1L, 41L, 28L, 14L, 2L, 42L, 3L, 15L, 29L, 6L, 18L, 32L,
45L, 9L, 48L, 21L, 35L, 10L, 36L, 22L, 49L, 1L, 40L, 27L, 41L,
28L, 14L, 2L, 29L, 15L, 3L, 42L, 18L, 32L, 45L, 6L, 9L, 21L,
48L, 35L, 10L, 22L, 49L, 36L, 1L, 27L, 40L, 2L, 14L, 41L, 28L,
42L, 29L, 15L, 3L, 18L, 32L, 6L, 45L, 46L, 7L, 33L, 19L, 35L,
21L, 9L, 48L, 10L, 49L, 22L, 36L, 6L, 32L, 18L, 45L, 10L, 22L,
36L, 49L, 40L, 1L, 27L, 41L, 14L, 28L, 2L, 29L, 3L, 15L, 42L,
18L, 32L, 6L, 45L, 46L, 7L, 19L, 33L, 48L, 9L, 21L, 35L, 36L,
49L, 22L, 10L, 6L, 32L, 18L, 45L, 49L, 22L, 10L, 36L, 27L, 1L,
40L, 2L, 14L, 41L, 28L, 15L, 29L, 3L, 42L, 18L, 45L, 6L, 32L,
9L, 21L, 35L, 48L, 10L, 36L, 49L, 22L, 40L, 1L, 27L, 14L, 41L,
28L, 2L, 3L, 15L, 42L, 29L, 18L, 32L, 6L, 45L, 48L, 35L, 9L,
21L, 10L, 49L, 36L, 22L, 45L, 32L, 6L, 18L, 36L, 22L, 49L, 10L,
18L, 6L, 45L, 32L, 10L, 36L, 49L, 22L, 1L, 40L, 27L, 2L, 14L,
28L, 41L, 42L, 3L, 15L, 29L, 32L, 6L, 45L, 18L, 33L, 46L, 7L,
19L, 48L, 9L, 21L, 35L, 22L, 49L, 36L, 10L, 32L, 45L, 6L, 18L,
22L, 36L, 10L, 49L, 41L, 28L, 14L, 2L, 6L, 18L, 32L, 45L, 49L,
22L, 10L, 36L, 1L, 27L, 40L, 2L, 14L, 41L, 28L, 15L, 29L, 42L,
3L, 6L, 45L, 32L, 18L, 19L, 7L, 46L, 33L, 21L, 9L, 35L, 48L,
36L, 49L, 10L, 22L, 1L, 27L, 40L, 30L, 43L, 4L, 40L, 1L, 27L,
41L, 2L, 28L, 14L, 3L, 42L, 29L, 15L, 44L, 31L, 17L, 5L, 6L,
32L, 18L, 45L, 33L, 46L, 19L, 7L, 21L, 9L, 35L, 48L, 10L, 22L,
49L, 36L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 29L, 42L, 3L, 15L,
45L, 18L, 6L, 32L, 33L, 19L, 46L, 7L, 21L, 35L, 9L, 48L, 10L,
36L, 49L, 22L, 40L, 1L, 27L, 18L, 45L, 32L, 6L, 22L, 36L, 10L,
49L, 40L, 1L, 27L, 2L, 14L, 28L, 41L, 3L, 15L, 29L, 42L, 6L,
32L, 45L, 18L, 46L, 33L, 7L, 19L, 48L, 35L, 21L, 9L, 22L, 36L,
10L, 49L, 28L, 14L, 2L, 41L, 32L, 18L, 6L, 45L, 49L, 10L, 22L,
36L, 2L, 28L, 41L, 14L, 32L, 6L, 45L, 18L, 10L, 49L, 36L, 22L,
45L, 32L, 18L, 6L, 10L, 22L, 49L, 36L, 6L, 32L, 18L, 45L, 36L,
10L, 22L, 49L, 18L, 6L, 45L, 32L, 10L, 36L, 22L, 49L, 40L, 1L,
27L, 28L, 2L, 14L, 41L, 3L, 29L, 15L, 42L, 45L, 32L, 6L, 18L,
35L, 21L, 48L, 9L, 22L, 49L, 10L, 36L, 14L, 41L, 2L, 28L, 18L,
45L, 6L, 32L, 10L, 49L, 36L, 22L, 18L, 32L, 45L, 6L, 22L, 36L,
49L, 10L, 14L, 41L, 28L, 2L, 32L, 6L, 45L, 18L, 49L, 36L, 10L,
22L, 41L, 2L, 14L, 28L, 6L, 45L, 18L, 32L, 10L, 22L, 49L, 36L,
6L, 32L, 45L, 18L, 49L, 22L, 36L, 10L, 41L, 28L, 14L, 2L, 6L,
45L, 18L, 32L, 22L, 10L, 49L, 36L, 1L, 27L, 40L, 28L, 2L, 14L,
41L, 42L, 29L, 15L, 3L, 45L, 6L, 18L, 32L, 9L, 21L, 35L, 48L,
10L, 36L, 49L, 22L, 27L, 1L, 40L, 14L, 28L, 41L, 2L, 15L, 29L,
42L, 3L, 18L, 45L, 32L, 6L, 46L, 19L, 7L, 33L, 9L, 35L, 21L,
48L, 49L, 36L, 22L, 10L, 1L, 40L, 27L, 28L, 14L, 2L, 41L, 15L,
42L, 29L, 3L, 32L, 6L, 18L, 45L, 7L, 33L, 19L, 46L, 48L, 35L,
21L, 9L, 10L, 36L, 49L, 22L, 27L, 1L, 40L, 48L, 9L, 35L, 21L,
14L, 41L, 2L, 28L, 45L, 18L, 6L, 32L, 49L, 10L, 36L, 22L, 1L,
40L, 27L, 2L, 28L, 14L, 41L, 15L, 3L, 42L, 29L, 18L, 6L, 45L,
32L, 33L, 19L, 7L, 46L, 9L, 48L, 21L, 35L, 10L, 49L, 22L, 36L,
2L, 41L, 14L, 28L, 45L, 32L, 18L, 6L, 49L, 10L, 22L, 36L, 1L,
40L, 27L, 41L, 14L, 28L, 2L, 15L, 29L, 42L, 3L, 17L, 31L, 44L,
5L, 18L, 32L, 45L, 6L, 33L, 7L, 46L, 19L, 9L, 35L, 48L, 21L,
36L, 10L, 22L, 49L, 2L, 14L, 41L, 28L, 45L, 6L, 32L, 18L, 36L,
22L, 10L, 49L, 41L, 14L, 28L, 2L, 18L, 45L, 32L, 6L, 49L, 22L,
36L, 10L, 40L, 27L, 1L, 41L, 2L, 14L, 28L, 42L, 29L, 3L, 15L,
32L, 45L, 18L, 6L, 46L, 19L, 33L, 7L, 9L, 48L, 21L, 35L, 10L,
49L, 36L, 22L, 1L, 40L, 27L, 41L, 28L, 14L, 2L, 3L, 29L, 15L,
42L, 6L, 18L, 32L, 45L, 46L, 7L, 33L, 19L, 9L, 48L, 21L, 35L,
36L, 10L, 49L, 22L, 14L, 28L, 2L, 41L, 45L, 18L, 32L, 6L, 10L,
22L, 36L, 49L, 1L, 27L, 40L, 14L, 2L, 41L, 28L, 29L, 15L, 3L,
42L, 18L, 45L, 32L, 6L, 22L, 10L, 49L, 36L, 27L, 40L, 1L, 14L,
28L, 41L, 2L, 29L, 15L, 42L, 3L, 32L, 45L, 6L, 18L, 7L, 46L,
19L, 33L, 21L, 9L, 48L, 35L, 49L, 36L, 22L, 10L, 27L, 1L, 40L,
28L, 41L, 14L, 2L, 15L, 3L, 29L, 42L, 18L, 32L, 6L, 45L, 46L,
19L, 33L, 7L, 21L, 48L, 35L, 9L, 49L, 36L, 22L, 10L, 28L, 2L,
14L, 41L, 32L, 18L, 45L, 6L, 22L, 10L, 49L, 36L, 40L, 1L, 27L,
28L, 14L, 41L, 2L, 15L, 42L, 3L, 29L, 6L, 45L, 18L, 32L, 48L,
21L, 9L, 35L, 22L, 36L, 49L, 10L, 14L, 41L, 28L, 2L, 45L, 6L,
18L, 32L, 36L, 22L, 10L, 49L, 40L, 27L, 1L, 5L, 44L, 17L, 31L,
35L, 9L, 21L, 48L, 27L, 1L, 40L, 14L, 2L, 28L, 41L, 15L, 29L,
3L, 42L, 45L, 6L, 32L, 18L, 36L, 10L, 22L, 49L, 28L, 2L, 14L,
41L, 15L, 29L, 42L, 3L, 18L, 45L, 32L, 6L, 46L, 7L, 33L, 19L,
9L, 48L, 21L, 35L, 49L, 36L, 10L, 22L, 1L, 40L, 27L, 14L, 28L,
2L, 41L, 42L, 3L, 15L, 29L, 18L, 32L, 45L, 6L, 9L, 21L, 48L,
35L, 36L, 49L, 22L, 10L, 1L, 40L, 27L, 41L, 2L, 28L, 14L, 3L,
42L, 15L, 29L, 45L, 6L, 18L, 32L, 48L, 9L, 21L, 35L, 36L, 22L,
10L, 49L, 40L, 1L, 27L, 14L, 41L, 2L, 28L, 15L, 42L, 3L, 29L,
6L, 32L, 45L, 18L, 33L, 19L, 7L, 46L, 35L, 48L, 9L, 21L, 36L,
22L, 49L, 10L, 6L, 18L, 45L, 32L, 22L, 10L, 49L, 36L, 6L, 18L,
32L, 45L, 36L, 10L, 22L, 49L, 2L, 14L, 28L, 41L, 45L, 18L, 32L,
6L, 22L, 49L, 10L, 36L, 2L, 28L, 14L, 41L, 32L, 6L, 18L, 45L,
10L, 36L, 49L, 22L, 14L, 28L, 2L, 41L, 18L, 32L, 6L, 45L, 22L,
49L, 36L, 10L, 28L, 41L, 14L, 2L, 18L, 6L, 45L, 32L, 10L, 22L,
49L, 36L, 41L, 14L, 2L, 28L, 18L, 32L, 45L, 6L, 36L, 49L, 10L,
22L, 1L, 27L, 40L, 41L, 28L, 14L, 2L, 3L, 29L, 42L, 15L, 32L,
6L, 45L, 18L, 46L, 7L, 33L, 19L, 21L, 48L, 35L, 9L, 10L, 22L,
49L, 36L, 1L, 27L, 40L, 28L, 41L, 14L, 2L, 15L, 29L, 3L, 42L,
6L, 18L, 45L, 32L, 33L, 7L, 19L, 46L, 9L, 35L, 21L, 48L, 10L,
22L, 36L, 49L, 41L, 2L, 14L, 28L, 32L, 6L, 45L, 18L, 22L, 49L,
10L, 36L, 2L, 14L, 28L, 41L, 32L, 18L, 6L, 45L, 22L, 49L, 36L,
10L, 18L, 6L, 45L, 32L, 22L, 10L, 36L, 49L, 40L, 1L, 27L, 48L,
21L, 9L, 35L, 27L, 40L, 1L, 28L, 14L, 2L, 41L, 42L, 15L, 29L,
3L, 32L, 45L, 18L, 6L, 21L, 35L, 9L, 48L, 36L, 10L, 22L, 49L,
40L, 1L, 27L, 41L, 28L, 14L, 2L, 42L, 29L, 3L, 15L, 45L, 6L,
32L, 18L, 46L, 7L, 19L, 33L, 48L, 35L, 21L, 9L, 49L, 22L, 10L,
36L, 41L, 2L, 14L, 28L, 6L, 18L, 45L, 32L, 10L, 49L, 22L, 36L,
2L, 28L, 41L, 14L, 32L, 6L, 45L, 18L, 10L, 22L, 49L, 36L, 40L,
1L, 27L, 2L, 41L, 14L, 28L, 3L, 29L, 42L, 15L, 45L, 32L, 18L,
6L, 9L, 35L, 21L, 48L, 22L, 10L, 36L, 49L, 1L, 40L, 27L, 28L,
41L, 14L, 2L, 3L, 29L, 15L, 42L, 45L, 32L, 6L, 18L, 35L, 21L,
9L, 48L, 10L, 49L, 22L, 36L, 27L, 1L, 40L, 35L, 9L, 48L, 21L,
27L, 1L, 40L, 9L, 48L, 21L, 35L, 40L, 1L, 27L, 2L, 14L, 28L,
41L, 3L, 42L, 29L, 15L, 18L, 32L, 6L, 45L, 21L, 35L, 9L, 48L,
36L, 22L, 10L, 49L, 14L, 28L, 41L, 2L, 5L, 31L, 17L, 44L, 32L,
45L, 6L, 18L, 22L, 49L, 36L, 10L, 1L, 27L, 40L, 2L, 14L, 28L,
41L, 42L, 29L, 3L, 15L, 45L, 32L, 18L, 6L, 33L, 19L, 46L, 7L,
21L, 35L, 9L, 48L, 10L, 22L, 36L, 49L, 40L, 1L, 27L, 28L, 41L,
2L, 14L, 29L, 3L, 42L, 15L, 32L, 18L, 6L, 45L, 22L, 10L, 49L,
36L, 41L, 28L, 14L, 2L, 45L, 6L, 32L, 18L, 36L, 49L, 10L, 22L,
18L, 45L, 6L, 32L, 36L, 22L, 49L, 10L, 45L, 32L, 6L, 18L, 36L,
10L, 49L, 22L, 1L, 40L, 27L, 14L, 28L, 41L, 2L, 15L, 42L, 3L,
29L, 18L, 32L, 6L, 45L, 7L, 46L, 33L, 19L, 9L, 21L, 48L, 35L,
49L, 22L, 36L, 10L, 41L, 14L, 28L, 2L, 32L, 45L, 6L, 18L, 49L,
36L, 22L, 10L, 6L, 32L, 45L, 18L, 10L, 22L, 49L, 36L, 18L, 27L,
1L, 40L, 41L, 28L, 2L, 14L, 42L, 29L, 3L, 15L, 45L, 6L, 18L,
32L, 33L, 46L, 7L, 19L, 48L, 9L, 21L, 35L, 10L, 22L, 36L, 49L,
40L, 27L, 1L, 15L, 3L, 42L, 29L, 6L, 32L, 18L, 45L, 10L, 36L,
22L, 49L, 1L, 27L, 40L, 28L, 41L, 2L, 14L, 3L, 15L, 29L, 42L,
6L, 18L, 32L, 45L, 35L, 9L, 48L, 21L, 10L, 22L, 36L, 49L, 32L,
45L, 6L, 18L, 36L, 10L, 22L, 49L, 27L, 40L, 1L, 9L, 21L, 35L,
48L, 27L, 1L, 40L, 29L, 42L, 3L, 15L, 18L, 27L, 1L, 40L, 14L,
2L, 28L, 41L, 42L, 15L, 3L, 29L, 6L, 18L, 32L, 45L, 48L, 35L,
9L, 21L, 49L, 22L, 36L, 10L, 43L, 4L, 30L, 40L, 27L, 1L, 2L,
28L, 41L, 14L, 29L, 42L, 3L, 15L, 45L, 32L, 18L, 6L, 33L, 7L,
46L, 19L, 35L, 48L, 9L, 21L, 36L, 22L, 49L, 10L, 14L, 28L, 41L,
2L, 18L, 45L, 32L, 6L, 49L, 22L, 10L, 36L, 40L, 27L, 1L, 41L,
2L, 14L, 28L, 29L, 15L, 42L, 3L, 6L, 45L, 32L, 18L, 48L, 9L,
21L, 35L, 36L, 49L, 22L, 10L, 27L, 40L, 1L, 14L, 28L, 41L, 2L,
29L, 15L, 3L, 42L, 32L, 6L, 45L, 18L, 21L, 9L, 48L, 35L, 10L,
36L, 49L, 22L, 1L, 27L, 40L, 28L, 14L, 2L, 41L, 42L, 3L, 29L,
15L, 45L, 18L, 32L, 6L, 33L, 7L, 46L, 19L, 35L, 9L, 48L, 21L,
36L, 10L, 22L, 49L, 40L, 1L, 27L, 14L, 41L, 28L, 2L, 15L, 29L,
3L, 42L, 32L, 45L, 18L, 6L, 9L, 48L, 35L, 21L, 10L, 36L, 49L,
22L, 40L, 1L, 27L, 28L, 2L, 14L, 41L, 42L, 15L, 3L, 29L, 45L,
6L, 18L, 32L, 33L, 19L, 46L, 7L, 35L, 21L, 9L, 48L, 49L, 22L,
36L, 10L, 40L, 27L, 1L, 28L, 41L, 2L, 14L, 29L, 42L, 3L, 15L,
6L, 45L, 32L, 18L, 33L, 19L, 7L, 46L, 48L, 9L, 21L, 35L, 36L,
49L, 10L, 22L, 14L, 41L, 28L, 2L, 45L, 18L, 32L, 6L, 10L, 22L,
36L, 49L, 32L, 45L, 6L, 18L, 10L, 49L, 36L, 22L, 28L, 2L, 14L,
41L, 6L, 32L, 45L, 18L, 10L, 36L, 22L, 49L, 27L, 1L, 40L, 41L,
2L, 28L, 14L, 15L, 42L, 3L, 29L, 32L, 6L, 45L, 18L, 19L, 7L,
33L, 46L, 35L, 21L, 9L, 48L, 36L, 49L, 22L, 10L, 28L, 14L, 2L,
41L, 32L, 6L, 18L, 45L, 36L, 49L, 10L, 22L), .Label = c("Apr 06 - Jun 06",
"Apr 07 - Jun 07", "Apr 08 - Jun 08", "Apr 09 - Jun 09", "Apr 10 - Jun 10",
"Apr 11 - Jun 11", "Apr 12 - Jun 12", "Apr 13 - Jun 13", "Apr 14 - Jun 14",
"Apr 15 - Jun 15", "Apr 16 - Jun 16", "Apr 17 - Jun 17", "Apr 18 - Jun 18",
"Jan 07 - Mar 07", "Jan 08 - Mar 08", "Jan 09 - Mar 09", "Jan 10 - Mar 10",
"Jan 11 - Mar 11", "Jan 12 - Mar 12", "Jan 13 - Mar 13", "Jan 14 - Mar 14",
"Jan 15 - Mar 15", "Jan 16 - Mar 16", "Jan 17 - Mar 17", "Jan 18 - Mar 18",
"Jan 19 - Mar 19", "Jul 06 - Sep 06", "Jul 07 - Sep 07", "Jul 08 - Sep 08",
"Jul 09 - Sep 09", "Jul 10 - Sep 10", "Jul 11 - Sep 11", "Jul 12 - Sep 12",
"Jul 13 - Sep 13", "Jul 14 - Sep 14", "Jul 15 - Sep 15", "Jul 16 - Sep 16",
"Jul 17 - Sep 17", "Jul 18 - Sep 18", "Oct 06 - Dec 06", "Oct 07 - Dec 07",
"Oct 08 - Dec 08", "Oct 09 - Dec 09", "Oct 10 - Dec 10", "Oct 11 - Dec 11",
"Oct 12 - Dec 12", "Oct 13 - Dec 13", "Oct 14 - Dec 14", "Oct 15 - Dec 15",
"Oct 16 - Dec 16", "Oct 17 - Dec 17", "Oct 18 - Dec 18"), class = "factor")
Is there a way of turning this into a data object using lubridate? I tried different things like this:
a <- as.numeric(df$Period)
library(lubridate)
a <- quarter(a, with_year = TRUE)
And many similar iterations of this, but I cannot really get it tight.
Thanks!
Assuming the input is as shown below we can split it into from and to.
Then convert to yearmon class which represents year/month as year + fraction where fraction = 0 for Jan, 1/12 for Feb, ..., 11/12 for Dec (so for example adding 1/12 to such an object increments it by one month) and displays as shown.
We also convert to yearqtr class which represents quarters as year + fraction where the fraction is 0, 1/4, 1/2 and 3/4 for successive quarters so, for example, adding 1/4 to such an object increments it by one quarter.
These objects display as shown below.
Note that the question states that Period is character but the dput output shows it has factor class, not character.
library(dplyr)
library(tidyr)
library(zoo)
df <- data.frame(Period = c("Jul 06 - Sep 06", "Oct 06 - Dec 06",
"Apr 06 - Jun 06", "Apr 08 - Jun 08"))
df %>%
separate(Period, c("from", "to"), sep = " - ") %>%
mutate(from = as.yearmon(from, "%b %y"),
to = as.yearmon(to, "%b %y"),
year_qtr = as.yearqtr(to),
year = as.integer(to),
qtr = cycle(year_qtr),
from_date = as.Date(from),
to_date = as.Date(to, frac = 1))
giving:
from to year_qtr year qtr from_date to_date
1 Jul 2006 Sep 2006 2006 Q3 2006 3 2006-07-01 2006-09-30
2 Oct 2006 Dec 2006 2006 Q4 2006 4 2006-10-01 2006-12-31
3 Apr 2006 Jun 2006 2006 Q2 2006 2 2006-04-01 2006-06-30
4 Apr 2008 Jun 2008 2008 Q2 2008 2 2008-04-01 2008-06-30

Conditional replace values in a column

I am trying to replace some key numbers with their respective people names.
Despite my two attempts, I cannot change the numbers (characters) into names, any suggestions?
Here is what I tried so far:
setDT(df)[person == "447745939698" , person := "John"]
and
df <- df %>% mutate(person=ifelse(person=="447745939698","John",person))
Dataset:
structure(list(person = c("Pavel", "Anna", "Julian", "Bernardo",
"Bryony", "KJ", "Filippo", "Duncan", "‪447761633878‬", "Josh",
"Alex", "Berna", "Melina", "Martha", "‪447999592975‬", "‪48512044757‬",
"Don", "‪447404192025‬", "Sofia", "Jonas", "Chantal", "‪447441458269‬",
"‪447745939698‬", "Sungjoo", "‪447850449670‬", "Blanche",
"Vedo", "‪966554857666‬", "‪447787327724‬", "‪447407102816‬",
"‪447972826119‬", "‪447516428644‬", "‪447973747720‬",
"‪447383865362‬", "‪447478422564‬", "‪447543834973‬",
"Cris", "‪31642688469‬", "‪447921148041‬", "‪447865832098‬",
"Steve", "‪447492829467‬", "Andrea", "‪447878829919‬",
"‪447880747575‬", "‪34635960936‬", "‪447464871555‬",
"‪31640838890‬", "‪46707218515‬", "‪4528822826‬",
"‪393480848355‬", "‪447568552037‬", "‪4580211317‬",
"‪551198299‑2336‬", "‪447935988040‬", "‪447340827646‬"
)), class = c("data.table", "data.frame"), row.names = c(NA,
-56L), index = structure(integer(0), "`__person`" = c(11L,
43L, 2L, 12L, 4L, 26L, 5L, 21L, 37L, 17L, 8L, 7L, 20L, 10L, 3L,
6L, 14L, 13L, 1L, 19L, 41L, 24L, 27L, 48L, 38L, 46L, 51L, 56L,
40L, 34L, 30L, 18L, 47L, 35L, 22L, 42L, 32L, 36L, 52L, 23L, 9L,
29L, 44L, 45L, 25L, 39L, 55L, 31L, 33L, 15L, 50L, 53L, 49L, 16L,
54L, 28L)))

strange error when creating a model with zelig

dput(t)
structure(list(Volume = c(2625941L, 4685483L, 3160694L, 2627816L,
2430273L, 2498011L, 2632445L, 3224434L, 2531941L, 5043867L, 2788003L,
3278796L, 3273977L, 3192613L, 3456297L, 2668175L, 2805861L, 2689392L,
2733510L, 3285889L, 2957370L, 3420479L, 3868692L, 4353776L, 3134759L,
2914727L, 3160491L, 3803716L, 3427911L, 2646258L, 3616962L, 3071943L,
3013008L, 4024996L, 4357129L, 3110560L, 3063334L, 4537971L, 1902002L,
2618413L, 2473005L, 2844029L, 2398462L, 3406776L, 3071573L, 3714231L,
4276458L, 3825187L, 2652650L, 3040994L, 2695117L, 3038566L, 2695652L,
2919113L, 2840214L, 2768958L, 5246649L, 3023172L, 3565584L, 2928450L,
3503840L, 2948165L, 3512192L, 3409995L, 3511665L, 3155152L, 3020401L,
2758133L, 2548245L, 3033309L, 2740213L, 2851881L, 3134557L, 4445879L,
3173913L, 3720477L, 3753070L, 3609973L, 3826284L, 4864280L, 4159588L,
3095322L, 3138732L, 3591433L, 3063357L, 3215559L, 3258059L, 3559727L,
4886550L, 4025763L, 4108614L, 5720774L, 4075195L, 3322352L, 3048940L,
3249172L, 3148053L, 3321660L, 3159642L, 3976820L, 3848960L, 3466783L,
3811408L, 6033563L, 4114751L, 3181385L, 2926695L, 2866148L, 2692198L,
3400891L, 2922295L, 3912049L, 3079066L, 2833293L, 3560196L, 3317644L,
3151086L, 3776538L, 5479510L, 3954497L, 3594429L, 3088262L, 2778180L,
3532457L), SLA = c(28L, 44L, 12L, 28L, 4L, 28L, 4L, 4L, 8L, 12L,
8L, 4L, 8L, 4L, 8L, 8L, 32L, 4L, 36L, 8L, 4L, 8L, 20L, 8L, 32L,
12L, 32L, 8L, 16L, 40L, 8L, 20L, 4L, 4L, 8L, 20L, 16L, 4L, 12L,
8L, 4L, 8L, 4L, 4L, 8L, 12L, 12L, 16L, 28L, 28L, 12L, 16L, 16L,
8L, 20L, 20L, 24L, 44L, 12L, 24L, 24L, 24L, 20L, 24L, 36L, 16L,
40L, 24L, 4L, 44L, 8L, 16L, 12L, 8L, 32L, 12L, 20L, 16L, 28L,
8L, 24L, 24L, 4L, 4L, 8L, 8L, 4L, 12L, 8L, 44L, 12L, 24L, 40L,
8L, 4L, 8L, 12L, 12L, 8L, 16L, 24L, 8L, 36L, 48L, 36L, 12L, 36L,
28L, 20L, 12L, 20L, 32L, 24L, 4L, 12L, 16L, 8L, 24L, 16L, 36L,
44L, 12L, 8L, 4L), Duration = c(21L, 25L, 15L, 13L, 15L, 20L,
17L, 20L, 12L, 15L, 31L, 12L, 24L, 16L, 25L, 13L, 13L, 20L, 21L,
20L, 26L, 15L, 26L, 21L, 27L, 20L, 34L, 29L, 74L, 62L, 33L, 27L,
26L, 23L, 30L, 26L, 26L, 18L, 19L, 13L, 25L, 18L, 20L, 18L, 37L,
20L, 22L, 25L, 24L, 22L, 42L, 17L, 18L, 18L, 28L, 18L, 28L, 32L,
23L, 31L, 12L, 30L, 40L, 30L, 18L, 18L, 19L, 27L, 21L, 31L, 23L,
26L, 14L, 22L, 21L, 21L, 26L, 30L, 21L, 23L, 12L, 22L, 24L, 29L,
36L, 19L, 21L, 25L, 24L, 29L, 26L, 34L, 33L, 17L, 17L, 24L, 19L,
18L, 12L, 18L, 11L, 19L, 22L, 48L, 49L, 25L, 16L, 43L, 18L, 18L,
19L, 15L, 38L, 19L, 22L, 28L, 28L, 34L, 16L, 53L, 38L, 23L, 27L,
17L)), .Names = c("Volume", "SLA", "Duration"), class = "data.frame", row.names = c(2L,
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, 75L, 76L, 77L, 79L, 80L, 81L, 82L, 84L,
85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L,
98L, 99L, 100L, 101L, 102L, 103L, 105L, 106L, 107L, 108L, 110L,
111L, 112L, 113L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L))
when I do this:
z.out1 <- zelig(Duration ~ Volume, model = "logit", data = t)
I get this error:
Error in `rownames<-`(`*tmp*`, value = c(1L, 0L)) :
attempt to set rownames on object with no dimensions
any ideas?

How can I sort one column based on another?

I have the following data:
points <- structure(list(A = structure(c(1L, 1L, 2L, 2L, 3L, 4L,
4L, 5L, 5L, 6L, 6L, 7L, 8L, 9L, 9L, 10L, 11L, 12L, 12L, 13L,
14L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 21L, 21L,
22L, 23L, 24L, 24L, 25L, 26L, 26L, 27L, 28L, 29L, 30L, 30L, 31L,
32L, 32L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L,
39L, 39L, 40L, 41L), .Label = c("00017dd3-f55e-e011-854c-00237de2db9e",
"0005f624-565a-e011-854c-00237de2db9e", "0007b82f-bfe0-4b55-963e-be5a2a1e7f7b",
"00095b52-fd0a-e011-9264-00237de2db9e", "00098835-9554-4898-8d4b-82d42b8b4464",
"000a727f-8334-e011-854c-00237de2db9e", "000c0a31-f459-4365-aa3a-1978deb89f67",
"000e36a4-6e56-4851-8d36-2caf0bdd63ec", "000f05a6-cf94-4518-8de7-1773cbea8198",
"00105574-a775-43e8-8472-c8b294e46786", "00112a96-3c47-409c-83bd-6f30d8d77100",
"0012f133-f68e-e011-986b-78e7d1fa76f8", "0012f899-1c45-4917-90b7-11bea31e467e",
"0014606b-17b7-46d6-957f-e23b43fcc773", "001478e2-3e50-486c-ae3b-d1ceb36f0fd0",
"00159bab-ce82-454a-9343-f7d8f1500a68", "0015b84e-a48d-443e-936e-cabdb80604dc",
"0018f8ba-c289-4483-bf74-5cd0e6c6ae9e", "0019487f-f31e-4e3e-b499-fd48077f71f9",
"00199523-c42f-47fd-a44a-066fb726f6dd", "0019dace-41e1-439f-8b73-328d02537fe7",
"001a346e-2a15-45d4-9fb1-6b4e2448d362", "001b0c90-5c86-4290-bad3-0d6794a6bfe8",
"001c0d0d-3059-e011-854c-00237de2db9e", "001c9cbb-8c79-4cbf-bc50-219a70ab20b8",
"001dcf83-7492-e011-986b-78e7d1fa76f8", "001dd5cf-3e3b-4ceb-823c-346c15f88878",
"001e0ef7-b977-436a-ab20-8c4af4f5b230", "001fc407-da48-4c42-9325-7756b160cbbd",
"001fdaa1-9471-e011-81d2-78e7d1fa76f8", "0020029f-2667-4c03-b99f-d803eccd27d4",
"00218e00-896e-e011-81d2-78e7d1fa76f8", "002196af-60c7-4baf-abdb-589b3a481686",
"0021a908-7ff6-df11-9264-00237de2db9e", "0021bced-909a-e011-986b-78e7d1fa76f8",
"0021f0fb-cb9f-e011-986b-78e7d1fa76f8", "00228254-9b20-4d40-a4a5-a7c608f81dfa",
"002357ba-5656-4308-bb92-6cc97f50d7aa", "0025eafd-a64f-e011-854c-00237de2db9e",
"0026b36c-ebc2-43f0-a0f7-72f43b70530b", "00277e09-543e-449a-8571-38f71a21cee2"
), class = "factor"), B = structure(c(10L, 10L, 27L,
27L, 28L, 23L, 23L, 38L, 38L, 24L, 24L, 19L, 35L, 26L, 26L, 28L,
5L, 36L, 36L, 21L, 11L, 1L, 14L, 14L, 4L, 4L, 9L, 9L, 16L, 16L,
3L, 7L, 7L, 13L, 37L, 17L, 17L, 29L, 15L, 15L, 12L, 31L, 32L,
8L, 8L, 2L, 30L, 30L, 39L, 6L, 6L, 22L, 22L, 20L, 20L, 34L, 34L,
18L, 18L, 33L, 33L, 25L, 29L), .Label = c("Aashu", "Actonica Studio",
"appyminds", "blackink", "BroeckiE", "Challenge Solutions LLC",
"CPP_MSP", "Datentechnik Innovation GmbH", "DerekM", "Dimension Srl",
"Dmitry Kazarin", "edg3", "fruitymo", "Geckosan", "Genera Interactive SL",
"HandyWare", "Infinite Square", "JTO.C Sq.", "JuJuZ", "Kitten Flavour",
"Krofita", "Mark Agholor", "MCTronix.com", "Michael Snow", "michaloxo",
"mobilewares.net", "NotoMedia LLC", "OKR", "P.F. CHAUVET", "Panoylhs",
"Pratik Gandhi", "raavr", "ReadBooks", "RGP", "Seesmic", "The KeitaCorp",
"viileetek", "Violineage", "Yalla Apps"), class = "factor"),
Date = structure(c(1302926400, 1302926400, 1302408000,
1302408000, 1327467600, 1292994000, 1292994000, 1322370000,
1322370000, 1297486800, 1297486800, 1326949200, 1321333200,
1314763200, 1314763200, 1328418000, 1327381200, 1307505600,
1307505600, 1325221200, 1324530000, 1327381200, 1326862800,
1326862800, 1326171600, 1326171600, 1325566800, 1325566800,
1327122000, 1327122000, 1320379200, 1324702800, 1324702800,
1327726800, 1327986000, 1301544000, 1301544000, 1332302400,
1308369600, 1308369600, 1325912400, 1331611200, 1325912400,
1304481600, 1304481600, 1325653200, 1304395200, 1304395200,
1322542800, 1294117200, 1294117200, 1309147200, 1309147200,
1309320000, 1309320000, 1313208000, 1313208000, 1325739600,
1325739600, 1300334400, 1300334400, 1325826000, 1321938000
), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("A",
"B", "Date"), row.names = c(NA, -63L), class = "data.frame")
I am trying to draw a scatter plot with the Y-axis sorted based on the date field. However, I am only able to do the following where I treat A as a factor. Any suggestions on how to achieve this?
p = ggplot(points, aes(Date, factor(A))) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE) +
scale_y_discrete("", breaks=NA)
The error comes when you ask ggplot to consider a date value as a discrete variable after just swapping the x and y positions. It goes away when you remove that:
p = ggplot(points, aes(x=A, y=Date)) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE)
p
Or you can get rid of the lines by applying the discrete axis call to the x-axis:
p = ggplot(points, aes(x=A, y=Date)) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE) +
scale_x_discrete("", breaks=NULL)
P
Unfortunately the title of the question doesn't seem to have a very clear connection to the text of the question, so I cannot tell if this was what you were asking for.

Resources