predicting regression fit into multiple other dataframes - r

Using R I've fit an ordered logistic regression to some data. I need to use the fitted values to predict future values. I have a dataset which has 10 different combinations of parameters I want to predict the probabilities for the 'Result' dependant variable (which the model is fit to). I've used 'split' to split into 10 separate dataframes and I want to try to run the predict statement against each of the outputted dataframes. Can someone show me how to:
a. Create a function to run the predict statement, and
b. Loop the function through the 10 dataframes?
c. Output the prediction probabilities for the three result conditions, and bind them to the relevant input dataframe
Here's what I've tried:
# Fit the model
library(MASS)
fit <- polr(Result ~ State + score1+ score2 + history + pastdefault, data = dat, Hess=TRUE)
## Model Summary
summary(fit)
#Take the new data which doesn't have predictions
t13<- dat[ which(dat$Tranche==13), ]
out <- split( t13 , f = r13$Gamen )
#Function
pred <- function(Result, State, score1, score2, history, pastdefault,...){
cbind(out, predict(fit, out, type = "probs"))}
#Use sapply to run prediction
pred.out <- sapply(out, pred)
Further to a suggestion I've tried running the predict statement against the result of splitting the data into 'out' as per code below:
#Predict against 'out' dataframes
newdat1 <- cbind(out, predict(fit, newdata=out, type = "probs"))
However I get the same error message:
in eval(expr, envir, enclos) : object 'State' not found
Here's what the data looks like using head(data):
State score1 score2 Salaries history exp moody Result pastdefault Tranche
1 Minnesota 6.000 17.5 35.948 9 579 1085 moreinfo yes 1
2 New Mexico 4.586 17.2 28.493 11 530 1015 fail No 1
3 Washington 5.906 20.2 36.151 48 494 937 fail No 1
4 West Virginia 6.107 14.8 31.944 17 484 932 moreinfo No 1
5 Louisiana 4.761 16.8 26.461 9 535 1021 pass yes 2
6 Oklahoma 4.845 15.5 28.172 9 536 1027 pass yes 2
Gamen
1 1
2 2
3 3
4 4
5 1
6 2
Here is the result of dput(data):
ture(list(State = structure(c(23L, 31L, 47L, 48L, 18L, 36L,
39L, 42L, 13L, 14L, 16L, 35L, 50L, 1L, 20L, 27L, 30L, 7L, 9L,
34L, 43L, 3L, 4L, 19L, 25L, 26L, 37L, 8L, 29L, 38L, 2L, 21L,
32L, 6L, 10L, 11L, 15L, 24L, 5L, 17L, 33L, 40L, 41L, 46L, 49L,
28L, 12L, 22L, 45L, 32L, 9L, 5L, 44L, 13L, 38L, 19L, 25L, 26L,
37L, 8L), .Label = c("Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts",
"Michigan", "Minnesota", "Mississippi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
"New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
"Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
"West Virginia", "Wisconsin", "Wyoming"), class = "factor"),
score1 = c(6, 4.586, 5.906, 6.107, 4.761, 4.845, 7.469, 4.388,
6.136, 5.826, 5.817, 6.162, 6.16, 4.405, 7.245, 5.935, 9.774,
8.817, 5.718, 4.775, 5.222, 4.778, 4.459, 6.428, 5.383, 5.692,
6.436, 7.03, 5.859, 7.109, 8.963, 7.287, 9.623, 5.443, 5.193,
6.078, 5.483, 4.08, 4.992, 5.217, 5.077, 4.797, 4.775, 5.327,
6.93, 5.16, 4.21, 6.994, 6.75, 5.859, 7.109, 8.963, 3.656,
7.287, 9.623, 5.443, 6.078, 5.483, 4.08, 4.992), score2 = c(17.5,
17.2, 20.2, 14.8, 16.8, 15.5, 14.7, 18.6, 17.3, 17.5, 15.1,
16.6, 14.9, 17.2, 17, 14.5, 13.8, 14.4, 19.1, 15.3, 15.7,
19.3, 17.1, 13.8, 15.5, 16.3, 19.9, 16.6, 15.6, 17.1, 17.6,
14.8, 15.2, 18.4, 16.3, 17.9, 15.8, 17.5, 24, 17, 16.2, 16.4,
14.4, 14.6, 15.9, 18.7, 19.1, 20.1, 13.8, 16.6, 15.6, 17.1,
24.3, 17.6, 14.8, 15.2, 24, 17, 16.2, 14.4), Salaries = c(35.948,
28.493, 36.151, 31.944, 26.461, 28.172, 40.729, 32.477, 39.431,
36.785, 34.652, 36.802, 31.285, 31.144, 40.661, 30.922, 46.087,
50.045, 32.588, 26.327, 31.223, 32.175, 28.934, 31.972, 31.189,
28.785, 38.555, 39.076, 34.72, 44.51, 47.951, 40.795, 47.612,
34.571, 32.291, 38.518, 31.511, 26.818, 41.078, 32.257, 30.793,
30.279, 25.994, 33.987, 37.746, 34.836, 29.783, 41.895, 35.406,
28.785, 38.555, 39.076, 29.082, 31.511, 26.818, 41.078, 32.257,
25.994, 33.987, 37.746), history = c(9L, 11L, 48L, 17L, 9L,
9L, 70L, 12L, 13L, 58L, 9L, 23L, 10L, 8L, 64L, 9L, 70L, 81L,
48L, 5L, 47L, 27L, 6L, 68L, 9L, 21L, 51L, 68L, 70L, 70L,
47L, 80L, 74L, 29L, 65L, 57L, 5L, 4L, 45L, 11L, 60L, 58L,
5L, 65L, 9L, 30L, 15L, 11L, 68L, 45L, 11L, 60L, 4L, 58L,
5L, 65L, 9L, 5L, 65L, 80L), exp = c(579L, 530L, 494L, 484L,
535L, 536L, 463L, 543L, 560L, 467L, 557L, 515L, 525L, 538L,
479L, 556L, 478L, 477L, 469L, 592L, 474L, 496L, 523L, 469L,
550L, 536L, 499L, 468L, 491L, 461L, 489L, 477L, 473L, 518L,
448L, 482L, 583L, 540L, 485L, 522L, 454L, 443L, 563L, 468L,
572L, 483L, 511L, 549L, 472L, 526L, 528L, 530L, 563L, 532L,
534L, 536L, 538L, 540L, 542L, 544L), moody = c(1085L, 1015L,
937L, 932L, 1021L, 1027L, 888L, 1040L, 1048L, 882L, 1060L,
975L, 1001L, 1029L, 909L, 1050L, 898L, 908L, 889L, 1107L,
893L, 944L, 1005L, 896L, 1045L, 1009L, 947L, 897L, 935L,
880L, 934L, 907L, 892L, 980L, 854L, 889L, 1099L, 1036L, 902L,
999L, 865L, 844L, 1068L, 896L, 1073L, 917L, 979L, 1033L,
901L, 1002L, 1007L, 1011L, 1076L, 1016L, 900L, 760L, 1029L,
850L, 1038L, 990L), Result = structure(c(3L, 2L, 2L, 3L,
4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 3L, 2L, 4L, 3L, 3L, 3L, 3L,
4L, 4L, 2L, 3L, 3L, 3L, 4L, 2L, 4L, 2L, 4L, 2L, 3L, 2L, 4L,
3L, 4L, 4L, 2L, 2L, 3L, 4L, 2L, 4L, 3L, 3L, 4L, 2L, 3L, 3L,
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("",
"fail", "moreinfo", "pass"), class = "factor"), pastdefault = structure(c(2L,
1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L), .Label = c("No",
"yes"), class = "factor"), Tranche = c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L,
9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 12L,
12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L), Gamen = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L, 5L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 1L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L)), .Names = c("State", "score1", "score2",
"Salaries", "history", "exp", "moody", "Result", "pastdefault",
"Tranche", "Gamen"), class = "data.frame", row.names = c(NA,
-60L))

Related

Stacked barplot with defined horizontal borders for each bar [duplicate]

I have data that i want to show in barplot in a way that i could'nt figure out how. Hope you can help me with this!
My table consists of 4 columns: cluster (0:6), IgG_Status (mild_high, mild_low,Severe_High), patient (1-16) and value (normalized value per each cluster). These are the lines of code i'm using now to create a barplot of the sum of values for each cluster, divided to IgG_Status (dodged style).
ggplot(mat, aes(x= cluster, fill= IgG_status, group=IgG_status)) + geom_bar(aes(weight = normalizedppstatus), position = "dodge")
I want to add to this graph horizontal lines that describe each patient contribution to the each bar. i managed to do it using facet_grid but it changed the whole style of the figure so it's not good for me. code for using facet_grid below:
ggplot(mat, aes(x= IgG_status , y= normalizedppstatus, fill= IgG_status)) + geom_col(color = "black") + facet_grid(~cluster) +
theme(axis.text.x = element_text(angle=30))
mat structure:
structure(list(cluster = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("0", "1", "2", "3", "4"), class = "factor"), IgG_status = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("mild_high", "mild_low", "Severe_High" ), class = "factor"), patient = structure(c(5L, 11L, 16L, 4L, 6L, 7L, 8L, 12L, 2L, 3L, 9L, 10L, 13L, 14L, 17L, 5L, 11L, 16L, 4L, 6L, 7L, 8L, 12L, 2L, 3L, 9L, 10L, 13L, 14L, 17L, 5L, 11L, 16L, 4L, 6L, 7L, 8L, 12L, 2L, 3L, 9L, 10L, 13L, 14L, 17L, 5L, 11L, 16L, 4L, 6L, 7L, 8L, 12L, 2L, 3L, 9L, 10L, 13L, 14L, 17L, 5L, 16L, 4L, 6L, 7L, 8L, 2L, 3L, 9L, 13L, 14L, 17L), .Label = c("Contact3", "CoV1", "CoV2", "CoV3", "CoV4", "CoV5", "CoV6", "CoV7", "CoV8", "CoV9", "CoV10", "CoV11", "CoV12", "CoV13", "CoV14", "CoV15", "CoV16"), class = "factor"), Freq = c(176L, 164L, 345L, 505L, 277L, 1421L, 679L, 104L, 235L, 933L, 692L, 682L, 133L, 1278L, 330L, 420L, 166L, 288L, 231L, 701L, 1105L, 431L, 506L, 180L, 814L, 410L, 363L, 283L, 182L, 268L, 657L, 155L, 82L, 872L, 385L, 277L, 23L, 298L, 87L, 128L, 469L, 640L, 197L, 148L, 73L, 688L, 220L, 51L, 263L, 456L, 312L, 693L, 303L, 120L, 400L, 373L, 35L, 62L, 170L, 166L, 7L, 530L, 5L, 1L, 80L, 876L, 19L, 7L, 2L, 4L, 15L, 153L), percentperstatus = c(0.0445682451253482, 0.041529501139529, 0.0873638895923018, 0.0467419474268789, 0.0256386523509811, 0.131525360977416, 0.0628470936690115, 0.00962606442058497, 0.0233807581335191, 0.0928265844194607, 0.0688488707591284, 0.0678539448811064, 0.0132325141776938, 0.127151527211223, 0.0328325539747289, 0.106356039503672, 0.0420359584704989, 0.0729298556596607, 0.021380970011107, 0.0648833765272121, 0.102276934468715, 0.0398926323583858, 0.0468345057386153, 0.0179086658043976, 0.0809869664709979, 0.0407919609989056, 0.0361158093722018, 0.0281564023480251, 0.018107650980002, 0.0266640135309919, 0.166371233223601, 0.0392504431501646, 0.0207647505697645, 0.0807108478341355, 0.0356349500185117, 0.0256386523509811, 0.00212884116993706, 0.0275823768974454, 0.00865585513879216, 0.0127350512386827, 0.0466620236792359, 0.0636752561934136, 0.0196000397970351, 0.0147249029947269, 0.00726295890956124, 0.174221321853634, 0.0557103064066852, 0.0129146619397316, 0.0243428359866716, 0.0422065901517956, 0.0288781932617549, 0.064142910033321, 0.0280451684561274, 0.011939110536265, 0.0397970351208835, 0.0371107352502239, 0.00348224057307731, 0.00616854044373694, 0.0169137399263755, 0.0165157695751667, 0.00177260065839453, 0.134211192707014, 0.00046279155868197, 9.25583117363939e-05, 0.00740466493891151, 0.0810810810810811, 0.00189035916824197, 0.000696448114615461, 0.000198985175604417, 0.000397970351208835, 0.00149238881703313, 0.0152223659337379), normalizedppstatus = c(0.0508788793021933, 0.0474098648043165, 0.0997341668139585, 0.0533603666644943, 0.0292689535961681, 0.150148675307419, 0.0717459187429537, 0.0109890656101137, 0.0266913531758627, 0.105970351119489, 0.0785975165859447, 0.077461714323142, 0.0151061700952755, 0.145155529186181, 0.0374814746724881, 0.142698157688979, 0.0563997480389775, 0.0978501652724429, 0.0286868996290798, 0.0870541845886795, 0.137225212511399, 0.0535240421650797, 0.0628379706160796, 0.0240281006032283, 0.10866041050571, 0.0547306735962423, 0.0484566695498438, 0.0377775137261868, 0.0242950794988198, 0.0357751720092511, 0.291165142146192, 0.0686919285124198, 0.0363402460517317, 0.141251495387918, 0.0623644790416841, 0.0448700277780429, 0.00372567017651619, 0.048271726634862, 0.0151485520846987, 0.0222875249062233, 0.0816628842267089, 0.111437624531117, 0.0343018938009843, 0.0257699506728207, 0.0127108540480805, 0.309787838022592, 0.0990600644839683, 0.0229639240394654, 0.0432846821009943, 0.0750487263804311, 0.0513491285760844, 0.114054314433418, 0.0498679037133128, 0.0212292686198854, 0.0707642287329512, 0.065987643293477, 0.00619187001413323, 0.0109684554536074, 0.0300747972115043, 0.0293671549241748, 0.00723736731183195, 0.547972096467276, 0.00188953585407682, 0.000377907170815364, 0.0302325736652291, 0.331046681634259, 0.00771816460016861, 0.00284353432637791, 0.000812438378965117, 0.00162487675793023, 0.00609328784223838, 0.0621515359908314)), row.names = c(5L, 11L, 16L, 21L, 23L, 24L, 25L, 29L, 36L, 37L, 43L, 44L, 47L, 48L, 51L, 56L, 62L, 67L, 72L, 74L, 75L, 76L, 80L, 87L, 88L, 94L, 95L, 98L, 99L, 102L, 107L, 113L, 118L, 123L, 125L, 126L, 127L, 131L, 138L, 139L, 145L, 146L, 149L, 150L, 153L, 158L, 164L, 169L, 174L, 176L, 177L, 178L, 182L, 189L, 190L, 196L, 197L, 200L, 201L, 204L, 209L, 220L, 225L, 227L, 228L, 229L, 240L, 241L, 247L, 251L, 252L, 255L), class = "data.frame")
Thanks!
library(tidyverse)
ggplot(mat, aes(x= cluster, fill= IgG_status, group=IgG_status)) +
geom_col(aes(y = normalizedppstatus), color = "white", position = "dodge")
By using geom_col, ggplot plots each patient as a bar, rather than calculating one grouped total to display with geom_bar. Adding a white border with the color aesthetic seems like the simplest way to separate the patients visually.

If-Else Statement in R with 3 conditions

I am trying to use an if-else statement to create a column in my data set. I want this if-else statement to create a column called "Surgical" in the df "option1" that displays the value of the column "Duration" subtracted by 20 ONLY IF the value in Duration is above 625, AND the factor "Single" is indicated in the column "Variability".
I have tried the following code:
option1$Surgical <- ifelse(option1$Variability == "Single", option1$Duration - 20, option1$Duration)
Any insight into how to specify the "only if the value is greater than 625" portion is appreciated!!
Df "option 1" for reference.
dput(option1)
structure(list(Stimulus = structure(c(36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 60L,
61L, 62L, 63L, 64L, 65L, 66L, 67L, 73L, 74L, 75L, 76L, 77L, 78L,
79L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 46L, 47L,
48L, 49L, 50L, 51L, 52L, 53L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
69L, 70L, 71L, 72L, 73L, 74L, 75L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 60L, 61L,
62L, 63L, 64L, 65L, 66L, 67L, 73L, 74L, 75L, 76L, 77L, 78L, 79L,
31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 46L, 47L, 48L,
49L, 50L, 51L, 52L, 53L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 69L,
70L, 71L, 72L, 73L, 74L, 75L, 7L, 9L, 12L, 18L, 28L, 26L, 51L,
37L, 3L, 2L, 19L, 14L, 27L, 23L, 65L, 77L, 7L, 9L, 12L, 18L,
28L, 26L, 51L, 37L, 3L, 2L, 19L, 14L, 27L, 23L, 65L, 77L, 5L,
11L, 20L, 16L, 30L, 25L, 35L, 33L, 7L, 9L, 12L, 18L, 28L, 26L,
51L, 37L, 5L, 11L, 20L, 16L, 30L, 25L, 35L, 33L, 7L, 9L, 12L,
18L, 28L, 26L, 51L, 37L), .Label = c("t1_block2_hoed3.mp3", "t1_block2_whod3.mp3",
"t1_block2_whod4.mp3", "t1_block2_whod5.mp3", "t1_block3_heed2.mp3",
"t1_block3_heed5.mp3", "t1_block3_hoed1.mp3", "t1_block3_hoed2.mp3",
"t1_block3_hoed4.mp3", "t1_block3_whod3.mp3", "t1_block4_heed5.mp3",
"t2_block1_hoed3.mp3", "t2_block1_whod1.mp3", "t2_block1_whod2.mp3",
"t2_block1_whod4.mp3", "t2_block2_heed3.mp3", "t2_block2_hoed5.mp3",
"t2_block3_hoed1.mp3", "t2_block3_whod1.mp3", "t2_block4_heed2.mp3",
"t2_block4_heed5.mp3", "t3_block1_heed1.mp3", "t3_block1_whod2.mp3",
"t3_block1_whod5.mp3", "t3_block2_heed5.mp3", "t3_block2_hoed2.mp3",
"t3_block2_whod5.mp3", "t3_block3_hoed1.mp3", "t3_block3_hoed4.mp3",
"t3_block4_heed3.mp3", "t4_block1_heed1.mp3", "t4_block1_heed2.mp3",
"t4_block1_heed3.mp3", "t4_block1_heed4.mp3", "t4_block1_heed5.mp3",
"t4_block1_hoed1.mp3", "t4_block1_hoed2.mp3", "t4_block1_hoed3.mp3",
"t4_block1_hoed4.mp3", "t4_block1_hoed5.mp3", "t4_block1_whod1.mp3",
"t4_block1_whod2.mp3", "t4_block1_whod3.mp3", "t4_block1_whod4.mp3",
"t4_block1_whod5.mp3", "t4_block2_heed1.mp3", "t4_block2_heed2.mp3",
"t4_block2_heed4.mp3", "t4_block2_heed5.mp3", "t4_block2_hoed1.mp3",
"t4_block2_hoed3.mp3", "t4_block2_hoed4.mp3", "t4_block2_hoed5.mp3",
"t4_block2_whod2.mp3", "t4_block2_whod4.mp3", "t4_block2_whod5.mp3",
"t4_block3_heed1.mp3", "t4_block3_heed4.mp3", "t4_block3_heed5.mp3",
"t4_block3_hoed1.mp3", "t4_block3_hoed2.mp3", "t4_block3_hoed4.mp3",
"t4_block3_hoed5.mp3", "t4_block3_whod1.mp3", "t4_block3_whod2.mp3",
"t4_block3_whod3.mp3", "t4_block3_whod5.mp3", "t4_block4_heed1.mp3",
"t4_block4_heed2.mp3", "t4_block4_heed3.mp3", "t4_block4_heed4.mp3",
"t4_block4_heed5.mp3", "t4_block4_hoed1.mp3", "t4_block4_hoed2.mp3",
"t4_block4_hoed3.mp3", "t4_block4_whod1.mp3", "t4_block4_whod2.mp3",
"t4_block4_whod3.mp3", "t4_block4_whod5.mp3"), class = "factor"),
Duration = c(497L, 517L, 580L, 563L, 569L, 486L, 506L, 536L,
545L, 554L, 516L, 600L, 607L, 577L, 537L, 583L, 544L, 566L,
567L, 616L, 652L, 564L, 517L, 612L, 564L, 632L, 662L, 565L,
594L, 622L, 552L, 542L, 539L, 554L, 600L, 607L, 577L, 497L,
517L, 580L, 563L, 569L, 594L, 563L, 623L, 602L, 516L, 600L,
607L, 577L, 531L, 642L, 624L, 566L, 567L, 616L, 652L, 654L,
576L, 556L, 608L, 632L, 662L, 565L, 497L, 517L, 580L, 563L,
569L, 486L, 506L, 536L, 545L, 554L, 516L, 600L, 607L, 577L,
537L, 583L, 544L, 566L, 567L, 616L, 652L, 564L, 517L, 612L,
564L, 632L, 662L, 565L, 594L, 622L, 552L, 542L, 539L, 554L,
600L, 607L, 577L, 497L, 517L, 580L, 563L, 569L, 594L, 563L,
623L, 602L, 516L, 600L, 607L, 577L, 531L, 642L, 624L, 566L,
567L, 616L, 652L, 654L, 576L, 556L, 608L, 632L, 662L, 565L,
452L, 547L, 510L, 663L, 470L, 503L, 600L, 517L, 491L, 505L,
641L, 581L, 520L, 485L, 517L, 622L, 452L, 547L, 510L, 663L,
470L, 503L, 600L, 517L, 491L, 505L, 641L, 581L, 520L, 485L,
517L, 622L, 510L, 458L, 558L, 638L, 483L, 538L, 577L, 600L,
452L, 547L, 510L, 663L, 470L, 503L, 600L, 517L, 510L, 458L,
558L, 638L, 483L, 538L, 577L, 600L, 452L, 547L, 510L, 663L,
470L, 503L, 600L, 517L), F0 = c(196L, 204L, 204L, 197L, 203L,
216L, 208L, 223L, 213L, 219L, 196L, 202L, 205L, 202L, 208L,
205L, 206L, 197L, 202L, 195L, 200L, 201L, 210L, 202L, 208L,
195L, 196L, 195L, 205L, 208L, 203L, 203L, 212L, 213L, 210L,
206L, 204L, 196L, 204L, 204L, 197L, 203L, 201L, 198L, 199L,
203L, 196L, 202L, 205L, 202L, 193L, 195L, 208L, 197L, 202L,
195L, 200L, 201L, 195L, 205L, 202L, 195L, 196L, 195L, 196L,
204L, 204L, 197L, 203L, 216L, 208L, 223L, 213L, 219L, 196L,
202L, 205L, 202L, 208L, 205L, 206L, 197L, 202L, 195L, 200L,
201L, 210L, 202L, 208L, 195L, 196L, 195L, 205L, 208L, 203L,
203L, 212L, 213L, 210L, 206L, 204L, 196L, 204L, 204L, 197L,
203L, 201L, 198L, 199L, 203L, 196L, 202L, 205L, 202L, 193L,
195L, 208L, 197L, 202L, 195L, 200L, 201L, 195L, 205L, 202L,
195L, 196L, 195L, 215L, 219L, 219L, 220L, 199L, 202L, 202L,
204L, 224L, 231L, 238L, 240L, 217L, 212L, 210L, 208L, 215L,
219L, 219L, 220L, 199L, 202L, 202L, 204L, 224L, 231L, 238L,
240L, 217L, 212L, 210L, 208L, 230L, 223L, 219L, 221L, 199L,
200L, 204L, 210L, 215L, 219L, 219L, 220L, 199L, 202L, 202L,
204L, 230L, 223L, 219L, 221L, 199L, 200L, 204L, 210L, 215L,
219L, 219L, 220L, 199L, 202L, 202L, 204L), F1 = c(576L, 553L,
579L, 586L, 601L, 398L, 390L, 398L, 389L, 404L, 587L, 560L,
562L, 553L, 393L, 397L, 382L, 553L, 592L, 556L, 571L, 387L,
392L, 398L, 400L, 580L, 580L, 554L, 403L, 391L, 388L, 393L,
382L, 375L, 384L, 392L, 388L, 576L, 553L, 579L, 586L, 601L,
387L, 393L, 402L, 406L, 587L, 560L, 562L, 553L, 388L, 391L,
412L, 553L, 592L, 556L, 571L, 410L, 404L, 401L, 420L, 580L,
580L, 554L, 576L, 553L, 579L, 586L, 601L, 398L, 390L, 398L,
389L, 404L, 587L, 560L, 562L, 553L, 393L, 397L, 382L, 553L,
592L, 556L, 571L, 387L, 392L, 398L, 400L, 580L, 580L, 554L,
403L, 391L, 388L, 393L, 382L, 375L, 384L, 392L, 388L, 576L,
553L, 579L, 586L, 601L, 387L, 393L, 402L, 406L, 587L, 560L,
562L, 553L, 388L, 391L, 412L, 553L, 592L, 556L, 571L, 410L,
404L, 401L, 420L, 580L, 580L, 554L, 620L, 630L, 602L, 605L,
571L, 573L, 560L, 553L, 434L, 417L, 306L, 319L, 414L, 419L,
392L, 391L, 620L, 630L, 602L, 605L, 571L, 573L, 560L, 553L,
434L, 417L, 306L, 319L, 414L, 419L, 392L, 391L, 448L, 441L,
293L, 291L, 420L, 420L, 388L, 384L, 620L, 630L, 602L, 605L,
571L, 573L, 560L, 553L, 448L, 441L, 293L, 291L, 420L, 420L,
388L, 384L, 620L, 630L, 602L, 605L, 571L, 573L, 560L, 553L
), F2 = c(1339L, 1381L, 1381L, 1347L, 1394L, 1484L, 1521L,
1539L, 1430L, 1454L, 1353L, 1378L, 1325L, 1357L, 1424L, 1563L,
1578L, 1350L, 1397L, 1273L, 1319L, 1548L, 1452L, 1499L, 1515L,
1358L, 1347L, 1248L, 1575L, 1438L, 1414L, 1548L, 3001L, 2916L,
2948L, 2973L, 2947L, 1339L, 1381L, 1381L, 1347L, 1394L, 2943L,
2913L, 2987L, 2940L, 1353L, 1378L, 1325L, 1357L, 3010L, 3008L,
2972L, 1350L, 1397L, 1273L, 1319L, 2963L, 2991L, 3007L, 2989L,
1358L, 1347L, 1248L, 1339L, 1381L, 1381L, 1347L, 1394L, 1484L,
1521L, 1539L, 1430L, 1454L, 1353L, 1378L, 1325L, 1357L, 1424L,
1563L, 1578L, 1350L, 1397L, 1273L, 1319L, 1548L, 1452L, 1499L,
1515L, 1358L, 1347L, 1248L, 1575L, 1438L, 1414L, 1548L, 3001L,
2916L, 2948L, 2973L, 2947L, 1339L, 1381L, 1381L, 1347L, 1394L,
2943L, 2913L, 2987L, 2940L, 1353L, 1378L, 1325L, 1357L, 3010L,
3008L, 2972L, 1350L, 1397L, 1273L, 1319L, 2963L, 2991L, 3007L,
2989L, 1358L, 1347L, 1248L, 1247L, 1244L, 1293L, 1264L, 1348L,
1354L, 1378L, 1381L, 1314L, 1233L, 1190L, 1208L, 1643L, 1659L,
1452L, 1438L, 1247L, 1244L, 1293L, 1264L, 1348L, 1354L, 1378L,
1381L, 1314L, 1233L, 1190L, 1208L, 1643L, 1659L, 1452L, 1438L,
2837L, 2816L, 2780L, 2776L, 2684L, 2718L, 2947L, 2948L, 1247L,
1244L, 1293L, 1264L, 1348L, 1354L, 1378L, 1381L, 2837L, 2816L,
2780L, 2776L, 2684L, 2718L, 2947L, 2948L, 1247L, 1244L, 1293L,
1264L, 1348L, 1354L, 1378L, 1381L), F3 = c(2831L, 2779L,
2915L, 2875L, 2712L, 2730L, 2793L, 2779L, 2772L, 2692L, 2718L,
2856L, 2674L, 2659L, 2717L, 2584L, 2829L, 2726L, 2685L, 2866L,
2793L, 2614L, 2636L, 2907L, 2822L, 2932L, 2882L, 2882L, 2650L,
2929L, 2809L, 2737L, 3623L, 3607L, 3584L, 3576L, 3680L, 2831L,
2779L, 2915L, 2875L, 2712L, 3641L, 3590L, 3556L, 3584L, 2718L,
2856L, 2674L, 2659L, 3640L, 3656L, 3686L, 2726L, 2685L, 2866L,
2793L, 3516L, 3552L, 3513L, 3579L, 2932L, 2882L, 2882L, 2831L,
2779L, 2915L, 2875L, 2712L, 2730L, 2793L, 2779L, 2772L, 2692L,
2718L, 2856L, 2674L, 2659L, 2717L, 2584L, 2829L, 2726L, 2685L,
2866L, 2793L, 2614L, 2636L, 2907L, 2822L, 2932L, 2882L, 2882L,
2650L, 2929L, 2809L, 2737L, 3623L, 3607L, 3584L, 3576L, 3680L,
2831L, 2779L, 2915L, 2875L, 2712L, 3641L, 3590L, 3556L, 3584L,
2718L, 2856L, 2674L, 2659L, 3640L, 3656L, 3686L, 2726L, 2685L,
2866L, 2793L, 3516L, 3552L, 3513L, 3579L, 2932L, 2882L, 2882L,
2711L, 3129L, 2786L, 2833L, 2754L, 2771L, 2856L, 2779L, 2909L,
2750L, 2866L, 2863L, 2804L, 2704L, 2636L, 2929L, 2711L, 3129L,
2786L, 2833L, 2754L, 2771L, 2856L, 2779L, 2909L, 2750L, 2866L,
2863L, 2804L, 2704L, 2636L, 2929L, 3226L, 3121L, 3867L, 3319L,
3426L, 3269L, 3680L, 3357L, 2711L, 3129L, 2786L, 2833L, 2754L,
2771L, 2856L, 2779L, 3226L, 3121L,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1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 4L, 4L,
4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("i", "o", "o ",
"u"), class = "factor"), F1.Mean = c(564L, 564L, 564L, 564L,
564L, 394L, 394L, 394L, 394L, 394L, 564L, 564L, 564L, 564L,
394L, 394L, 394L, 564L, 564L, 564L, 564L, 394L, 394L, 394L,
394L, 564L, 564L, 564L, 394L, 394L, 394L, 394L, 398L, 398L,
398L, 398L, 398L, 564L, 564L, 564L, 564L, 564L, 398L, 398L,
398L, 398L, 564L, 564L, 564L, 564L, 398L, 398L, 398L, 564L,
564L, 564L, 564L, 398L, 398L, 398L, 398L, 564L, 564L, 564L,
564L, 564L, 564L, 564L, 564L, 394L, 394L, 394L, 394L, 394L,
564L, 564L, 564L, 564L, 394L, 394L, 394L, 564L, 564L, 564L,
564L, 394L, 394L, 394L, 394L, 564L, 564L, 564L, 394L, 394L,
394L, 394L, 398L, 398L, 398L, 398L, 398L, 564L, 564L, 564L,
564L, 564L, 398L, 398L, 398L, 398L, 564L, 564L, 564L, 564L,
398L, 398L, 398L, 564L, 564L, 564L, 564L, 398L, 398L, 398L,
398L, 564L, 564L, 564L, 627L, 627L, 614L, 614L, 614L, 614L,
566L, 566L, 432L, 432L, 327L, 327L, 415L, 415L, 393L, 393L,
627L, 627L, 614L, 614L, 614L, 614L, 566L, 566L, 432L, 432L,
327L, 327L, 415L, 415L, 393L, 393L, 397L, 397L, 292L, 292L,
417L, 417L, 398L, 398L, 627L, 627L, 614L, 614L, 614L, 614L,
566L, 566L, 397L, 397L, 292L, 292L, 417L, 417L, 398L, 398L,
627L, 627L, 614L, 614L, 614L, 614L, 566L, 566L), F2.Mean = c(1328L,
1328L, 1328L, 1328L, 1328L, 1496L, 1496L, 1496L, 1496L, 1496L,
1328L, 1328L, 1328L, 1328L, 1496L, 1496L, 1496L, 1328L, 1328L,
1328L, 1328L, 1496L, 1496L, 1496L, 1496L, 1328L, 1328L, 1328L,
1496L, 1496L, 1496L, 1496L, 2969L, 2969L, 2969L, 2969L, 2969L,
1328L, 1328L, 1328L, 1328L, 1328L, 2969L, 2969L, 2969L, 2969L,
1328L, 1328L, 1328L, 1328L, 2969L, 2969L, 2969L, 1328L, 1328L,
1328L, 1328L, 2969L, 2969L, 2969L, 2969L, 1328L, 1328L, 1328L,
1328L, 1328L, 1328L, 1328L, 1328L, 1496L, 1496L, 1496L, 1496L,
1496L, 1328L, 1328L, 1328L, 1328L, 1496L, 1496L, 1496L, 1328L,
1328L, 1328L, 1328L, 1496L, 1496L, 1496L, 1496L, 1328L, 1328L,
1328L, 1496L, 1496L, 1496L, 1496L, 2969L, 2969L, 2969L, 2969L,
2969L, 1328L, 1328L, 1328L, 1328L, 1328L, 2969L, 2969L, 2969L,
2969L, 1328L, 1328L, 1328L, 1328L, 2969L, 2969L, 2969L, 1328L,
1328L, 1328L, 1328L, 2969L, 2969L, 2969L, 2969L, 1328L, 1328L,
1328L, 1250L, 1250L, 1247L, 1247L, 1247L, 1247L, 1357L, 1357L,
1292L, 1292L, 1157L, 1157L, 1746L, 1746L, 1455L, 1455L, 1250L,
1250L, 1247L, 1247L, 1247L, 1247L, 1357L, 1357L, 1292L, 1292L,
1157L, 1157L, 1746L, 1746L, 1455L, 1455L, 2828L, 2828L, 2763L,
2763L, 2721L, 2721L, 2969L, 2969L, 1250L, 1250L, 1247L, 1247L,
1247L, 1247L, 1357L, 1357L, 2828L, 2828L, 2763L, 2763L, 2721L,
2721L, 2969L, 2969L, 1250L, 1250L, 1247L, 1247L, 1247L, 1247L,
1357L, 1357L), Distance = c(16L, 54L, 55L, 29L, 76L, 13L,
25L, 43L, 66L, 43L, 34L, 50L, 4L, 31L, 72L, 67L, 83L, 25L,
74L, 56L, 11L, 52L, 44L, 5L, 20L, 34L, 25L, 81L, 80L, 58L,
82L, 52L, 36L, 58L, 25L, 7L, 24L, 16L, 54L, 55L, 29L, 76L,
28L, 56L, 18L, 30L, 34L, 50L, 4L, 31L, 42L, 40L, 14L, 25L,
74L, 56L, 11L, 13L, 23L, 38L, 30L, 34L, 25L, 81L, 16L, 54L,
55L, 29L, 76L, 13L, 25L, 43L, 66L, 43L, 34L, 50L, 4L, 31L,
72L, 67L, 83L, 25L, 74L, 56L, 11L, 52L, 44L, 5L, 20L, 34L,
25L, 81L, 80L, 58L, 82L, 52L, 36L, 58L, 25L, 7L, 24L, 16L,
54L, 55L, 29L, 76L, 28L, 56L, 18L, 30L, 34L, 50L, 4L, 31L,
42L, 40L, 14L, 25L, 74L, 56L, 11L, 13L, 23L, 38L, 30L, 34L,
25L, 81L, 8L, 7L, 48L, 19L, 110L, 115L, 22L, 27L, 22L, 61L,
39L, 52L, 103L, 87L, 3L, 17L, 8L, 7L, 48L, 19L, 110L, 115L,
22L, 27L, 22L, 61L, 39L, 52L, 103L, 87L, 3L, 17L, 52L, 46L,
17L, 13L, 37L, 4L, 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istent"), class = "factor"),
Fake = c(477, 497, 560, 543, 549, 466, 486, 516, 525, 534,
496, 580, 587, 557, 517, 563, 524, 546, 547, 596, 632, 544,
497, 592, 544, 612, 642, 545, 574, 602, 532, 522, 519, 534,
580, 587, 557, 477, 497, 560, 543, 549, 574, 543, 603, 582,
496, 580, 587, 557, 511, 622, 604, 546, 547, 596, 632, 634,
556, 536, 588, 612, 642, 545, 477, 497, 560, 543, 549, 466,
486, 516, 525, 534, 496, 580, 587, 557, 517, 563, 524, 546,
547, 596, 632, 544, 497, 592, 544, 612, 642, 545, 574, 602,
532, 522, 519, 534, 580, 587, 557, 477, 497, 560, 543, 549,
574, 543, 603, 582, 496, 580, 587, 557, 511, 622, 604, 546,
547, 596, 632, 634, 556, 536, 588, 612, 642, 545, 452, 547,
510, 663, 470, 503, 600, 517, 491, 505, 641, 581, 520, 485,
517, 622, 452, 547, 510, 663, 470, 503, 600, 517, 491, 505,
641, 581, 520, 485, 517, 622, 510, 458, 558, 638, 483, 538,
577, 600, 452, 547, 510, 663, 470, 503, 600, 517, 510, 458,
558, 638, 483, 538, 577, 600, 452, 547, 510, 663, 470, 503,
600, 517), Check = c(20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0)), row.names = c(NA, -192L), class = "data.frame")
We can check multiple conditions with & or |. Here, we would need & because both the conditions should be satisfied
option1$Surgical <- ifelse(option1$Variability == "Single" &
option1$Duration > 625, option1$Duration - 20, option1$Duration)
You can do this directly without using ifelse :
option1$Surgical <- with(option1, Duration - (20 *
(Variability == 'Single' & Duration > 625)))
Here, we take advantage of the fact that
20 * TRUE #gives
#[1] 20
and
20 * FALSE #gives
#[1] 0
So whenever the condition (Variability == 'Single' & Duration > 625) is TRUE it subtracts 20 from Duration or else 0.

Why does strip text color from facet_wrap not correspond to element_text color?

Please, find my data sample p below.
Question: why does the strip text color from facet_wrap() not change as specified in element_text(colour)?
I have produced this plot
I would like the strip text color (UICC Stage I, II, III and IV) to match the color of the geom_point as specified in cols. It currently loads #E1B930 on all text items.
What is wrong with the following script?
cols = c("#E1B930", "#2C77BF","#E38072","#6DBCC3")
ggplot(p, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(strip.text.x = element_text(size=12,face="bold", colour = cols),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(fill="white"),
legend.position="none")
My data
p <- structure(list(uiccc = structure(c(4L, 3L, 3L, 2L, 2L, 2L, 2L,
4L, 1L, 1L, 2L, 1L, 4L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 2L,
3L, 2L, 4L, 1L, 1L, 2L, 4L, 4L, 1L, 3L, 3L, 4L, 3L, 1L, 4L, 2L,
3L, 4L, 4L, 4L, 3L, 2L, 4L, 1L, 4L, 2L, 4L, 4L, 2L, 4L, 4L, 1L,
4L, 2L, 3L, 2L, 2L, 3L, 2L, 4L, 4L, 2L, 2L, 3L, 1L, 4L, 4L, 4L,
4L, 4L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 4L,
2L, 4L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 3L,
3L, 4L, 1L, 1L, 3L, 1L, 4L, 2L, 1L, 3L, 1L, 2L, 1L, 1L, 4L, 1L,
1L, 4L, 1L, 1L, 3L, 2L, 2L, 1L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 2L,
2L, 4L, 4L, 2L, 3L, 4L, 2L, 4L, 1L, 1L, 3L, 3L, 1L, 1L, 3L, 4L,
4L, 2L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 2L, 2L, 4L, 3L,
1L, 4L, 3L, 4L, 4L, 3L, 1L, 4L, 4L, 4L, 4L, 2L, 2L, 4L, 4L, 1L,
4L, 4L, 2L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 4L, 2L, 4L, 4L, 2L,
4L, 4L, 4L, 4L, 1L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 3L, 1L, 2L, 1L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 1L,
3L, 4L, 4L, 1L, 3L, 3L, 4L, 3L), .Label = c("UICC Stage I", "UICC Stage II",
"UICC Stage III", "UICC Stage IV"), class = "factor"), os.neck = c(11.5,
74.38, 17.02, 7.89, 96.03, 40.48, 17.74, 14.65, 62.46, 12.55,
9.92, 26.05, 45.47, 17.38, 39.72, 51.45, 8.61, 76.98, 67.09,
94.79, 72.15, 93.93, 17.05, 12.48, 91.6, 15.87, 11.04, 67.22,
67.02, 8.94, 6.6, 5.09, 10.68, 17.15, 0.07, 5.19, 40.77, 0.2,
170.88, 5.55, 1.61, 38.28, 10.58, 32.99, 110.98, 103.69, 122.32,
14.78, 42.74, 4.04, 8.28, 84.96, 11.7, 49.97, 120.48, 52.6, 71.26,
16.3, 100.14, 55.03, 6.51, 89.89, 51.71, 24.97, 55.66, 21.91,
81.48, 30.92, 1.58, 7.52, 30.75, 3.45, 19.22, 5.42, 17.68, 45.54,
76.22, 125.34, 83.62, 30.82, 90.32, 1.84, 19.98, 20.53, 32.59,
54.77, 2.3, 106.84, 22.28, 45.18, 4.47, 39.66, 32.3, 16.23, 3.88,
2.23, 0.23, 18.73, 0.79, 28.75, 79.54, 14.46, 15.15, 54.97, 48.59,
34.83, 58.42, 35.29, 45.73, 57.53, 63.11, 65.05, 29.54, 77.21,
63.48, 83.35, 34.3, 64.49, 29.54, 62.69, 21.62, 49.35, 99.02,
15.8, 41.89, 12.98, 13.8, 43.6, 57.23, 31.38, 70.74, 39.46, 20.76,
67.22, 127.15, 74.12, 1.97, 7.39, 25.17, 28.22, 14, 36.53, 20.83,
19.55, 40.77, 27.76, 45.31, 34.46, 35.55, 26.94, 9.43, 10.51,
6.8, 8.18, 8.02, 14.29, 6.11, 13.8, 4.9, 4.04, 14.82, 11.66,
73.07, 92.91, 99.98, 10.64, 10.05, 95.8, 7.23, 12.81, 43.99,
13.9, 10.25, 16.36, 18.2, 18.76, 12.32, 8.64, 11.79, 112.04,
70.97, 31.28, 28.85, 21.49, 19.94, 22.14, 29.44, 67.62, 11.01,
45.24, 110.72, 20.24, 14.06, 12.88, 31.51, 8.08, 13.08, 21.45,
24.28, 21.98, 32.89, 23.26, 15.41, 15.41, 13.8, 40.12, 8.02,
15.77, 49.81, 18.17, 24.21, 47.08, 6.6, 37.16, 13.01, 8.38, 14.36,
18.27, 17.28, 73.76, 68.21, 22.83, 2.66, 69.06, 17.05, 8.61,
23.33, 13.34, 12.65, 8.77, 128.92, 16.1, 4.99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3L, 16L, 4L, 6L, 10L, 13L, 33L, 16L, 6L, 9L,
23L, 9L, 8L, 13L, 5L, 30L, 25L, 3L, 9L, 9L, 12L, 7L, 38L, 5L,
7L, 15L, 4L, 6L, 15L, 9L, 8L, 7L, 4L, 6L, 10L, 8L, 4L, 9L, 10L,
14L, 14L, 3L, 4L, 6L, 6L, 20L, 3L, 26L, 13L, 13L, 13L, 13L, 3L,
7L, 6L, 5L, 10L, 15L, 29L, 7L, 6L, 11L, 17L, 14L, 18L, 22L, 9L,
20L, 34L, 9L, 8L, 8L, 11L, 3L, 4L, 4L, 5L, 3L, 2L, 8L, 5L, 18L,
7L, 9L, 13L, 18L, 19L, 14L, 46L, 23L, 11L, 6L, 18L, 20L, 4L,
2L, 7L, 7L, 4L, 11L, 13L, 13L, 9L, 9L, 9L, 12L, 11L, 16L, 6L,
13L, 8L, 17L, 5L, 8L, 22L, 19L, 3L, 15L, 14L, 7L, 18L, 9L, 10L,
18L, 24L, 11L, 15L, 7L, 6L, 4L, 24L, 23L, 8L, 20L, 9L, 22L, 11L,
2L, 24L, 15L, 5L, 8L, 11L, 11L, 11L, 15L, 6L, 16L, 7L, 9L, 16L,
11L, 33L, 27L, 16L, 57L, 5L, 7L, 8L, 11L, 15L, 15L, 12L, 5L,
9L, 49L, 11L, 28L, 19L, 13L, 23L, 11L, 12L, 10L, 4L, 14L, 6L,
12L, 32L, 13L, 12L, 4L, 11L, 17L, 10L, 5L, 15L, 21L, 19L, 11L,
31L, 9L, 20L, 11L, 16L, 12L, 6L, 16L, 27L, 30L, 18L, 18L, 10L,
7L, 23L, 16L, 15L, 4L, 12L, 9L, 10L, 11L, 7L, 8L, 8L, 7L, 6L,
9L, 9L, 13L, 15L, 12L, 35L, 12L, 5L, 19L, 27L, 34L, 10L, 16L,
18L, 6L, 22L)), row.names = c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 20L, 22L, 24L, 28L, 29L,
31L, 34L, 35L, 39L, 40L, 42L, 43L, 44L, 47L, 48L, 49L, 50L, 54L,
56L, 57L, 58L, 59L, 60L, 62L, 63L, 66L, 67L, 68L, 69L, 70L, 71L,
72L, 73L, 74L, 75L, 76L, 80L, 81L, 82L, 83L, 86L, 87L, 88L, 89L,
94L, 97L, 99L, 101L, 102L, 106L, 113L, 115L, 117L, 122L, 129L,
132L, 136L, 142L, 143L, 145L, 146L, 148L, 153L, 154L, 158L, 159L,
163L, 164L, 167L, 169L, 171L, 174L, 175L, 178L, 179L, 185L, 188L,
191L, 197L, 210L, 218L, 220L, 230L, 236L, 238L, 239L, 240L, 241L,
242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 252L, 253L,
254L, 255L, 256L, 257L, 258L, 259L, 261L, 262L, 263L, 264L, 265L,
266L, 270L, 275L, 277L, 278L, 280L, 282L, 284L, 286L, 289L, 293L,
295L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 308L, 310L, 312L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L,
325L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L,
338L, 348L, 349L, 351L, 352L, 353L, 354L, 357L, 358L, 359L, 360L,
361L, 362L, 363L, 365L, 366L, 368L, 371L, 372L, 374L, 376L, 378L,
379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L,
390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L,
401L, 402L, 403L, 405L, 407L, 409L, 410L, 411L, 412L, 413L, 414L,
415L, 416L, 417L, 418L, 419L, 421L, 422L, 424L, 425L, 426L, 427L,
428L, 429L, 430L), class = "data.frame")
This is a modification of grob values for strip.text color using the grid package:
library(grid)
library(ggplot2)
g <- ggplot_gtable(ggplot_build(plot))
strip_both <- which(grepl('strip-', g$layout$name))
colors = c("#E38072","#6DBCC3", "#E1B930", "#2C77BF")
k <- 1
for (i in strip_both) {
j <- which(grepl("text", g$grobs[[i]]$grobs[[1]]$childrenOrder))
g$grobs[[i]]$grobs[[1]]$children[[j]]$children[[1]]$gp$col <- colors[k]
k <- k+1
}
grid.draw(g)
Assigning plot object to plot:
cols = c("#E1B930", "#2C77BF","#E38072","#6DBCC3")
plot <- ggplot(p, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(strip.text.x = element_text(size=12,face="bold"),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(fill="white"),
legend.position="none")
Alternatively, plot them per group, then combine:
# named colours per group
cols <- setNames(c("#E1B930", "#2C77BF","#E38072","#6DBCC3"),
levels(p$uiccc))
# set pretty limits
Xlim <- round(range(p$n.fjernet), -1)
Ylim <- round(range(p$os.neck), -1)
ggList <- lapply(split(p, p$uiccc), function(i){
title <- i[1, "uiccc"]
ggplot(i, aes(x = n.fjernet, y = os.neck)) +
geom_point(aes(color = uiccc), shape = 20, size = 5, alpha = 0.7, show.legend = FALSE) +
geom_quantile(quantiles = 0.5, col = "black", size = 1, linetype = 2) +
ggtitle(title) +
scale_fill_manual(values = cols) +
scale_colour_manual(values = cols) +
scale_x_continuous(limits = Xlim) +
scale_y_continuous(limits = Ylim) +
theme_classic() +
theme(plot.title = element_text(colour = cols[ title ]))
})
Then use patchwork or cowplot to combine:
patchwork::wrap_plots(ggList)
#or
cowplot::plot_grid(plotlist = ggList)
Alternatively to #Greg's answer (that I think should be the validated answer), you can get the same plot by adding annotation in place of facet labeling:
library(tidyverse)
ggplot(df, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(#strip.text.x = element_text(size=12,face="bold", colour = cols),
#strip.text.y = element_text(size=12, face="bold"),
#strip.background = element_rect(fill="white"),
strip.background = element_blank(),
strip.text = element_text(color = "transparent"),
legend.position="none",
plot.margin = unit(c(1,3,1,1), "lines")) +
coord_cartesian(clip = "off",ylim = c(0,175))+
geom_text(data = . %>% distinct(uiccc),
aes(label = factor(uiccc), color = uiccc), y = 200, x = 30, hjust = 0.5, fontface = "bold")

Cowplot Package: Aligning text labels in the top lefthand corner of plot space using plot_grid() in R

Overview:
I have produced a series of maps (see below) using the R-code below, and I used plot_grid() in the Cowplot package to arrange the plots using the two data frames below called "QuercusRobur 1" and "QuercusRobur2".
Problem:
The plots look really good; however, the text labels are not well aligned. A few labels overlay the top of y-axis called Latitude, and two of the text labels called "A: Urbanisation Index" and "B: Urbanisation Index" are not positioned above their plots, and they also overlay the main titles called "Observation Period 1" and "Observation Period 2".
Does anyone know how to neatly align the plot labels so they are positioned in the top lefthand corner of each plot but also prevent them from overlaying the y-axis or parts of the map (see desired output below)?
If anyone can help, I would be deeply appreciative
R-Code
##Import Packages
library(ggplot2)
library(maps)
library(mapdata)
library(tidyverse)
##Get a map of the UK from maps:
UK <- map_data(map = "world", region = "UK")
head(UK)
dim(UK)
##Produce point data
MapUK<-ggplot(data = UK, aes(x = long, y = lat, group = group)) +
geom_polygon() +
coord_map()
##head
head(QuercusRobur1)
head(QuercusRobur2)
##Remove weird data points
QuercusRobur1<-QuercusRobur1%>%filter(Longitude<=3)
##Observation 1
p1 <- ggplot(QuercusRobur1,
aes(x = Longitude, y = Latitude)) +
geom_polygon(data = UK,
aes(x = long, y = lat, group = group),
inherit.aes = FALSE) +
geom_point() +
coord_map(xlim = c(-10, 5)) + #limits added as there are some points really far away
theme_classic()
Urban1<-p1 +
aes(color = Urbanisation_index) +
scale_color_discrete(name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural"))
Stand1<-p1 +
aes(color = Stand_density_index) +
scale_color_discrete(name = "Stand Density Index",
labels = c("Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"))
Phenology1<-p1 +
aes(color = factor(Phenological_Index)) +
scale_color_discrete(name = "Phenological Index",
labels = c("No indication of autumn timing",
"First autumn tinting",
"Partial autumn tinting (>25% of leaves)",
"Advanced autumn tinting (>75% of leaves)"))
##Observation 2
p2 <- ggplot(QuercusRobur2,
aes(x = Longitude, y = Latitude)) +
geom_polygon(data = UK,
aes(x = long, y = lat, group = group),
inherit.aes = FALSE) +
geom_point() +
coord_map(xlim = c(-10, 5)) + #limits added as there are some points really far away
theme_classic()
Urban2<-p2 +
aes(color = Urbanisation_index) +
scale_color_discrete(name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural"))
Stand2<-p2 +
aes(color = Stand_density_.index) +
scale_color_discrete(name = "Stand Density Index",
labels = c("Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"))
Phenology2<-p2 +
aes(color = factor(Phenological_Index)) +
scale_color_discrete(name = "Phenological Index",
labels = c("No indication of autumn timing",
"First autumn tinting",
"Partial autumn tinting (>25% of leaves)",
"Advanced autumn tinting (>75% of leaves)"))
##Arrange the individual plots into one main plot
plot_grid(Urban1 + ggtitle("Observational Period 1"),
Urban2 + ggtitle("Observational Period 2"),
Stand1,
Stand2,
Phenology1,
Phenology2,
labels=c("A: Urbanisation Index", "B: Urbanisation Index",
"C: Stand Density Index","D: Stand Density Index",
"E: Phenological Index","F: Phenological Index"),
align = "v",
label_fontface="bold",
label_fontfamily="Times New Roman",
label_size = 8,
rel_widths = c(1, 1.3),
ncol = 2,
nrow = 3,
hjust = 0,
label_x = 0.01)
Plot produced from R-code
Desired Output
Data frame - QuercusRobur1
structure(list(Obs_.no = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 28L, 29L, 30L, 31L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 44L, 45L, 46L, 47L, 57L, 58L, 59L, 60L,
61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 74L,
75L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 93L,
102L, 103L, 104L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L,
120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L,
131L, 135L, 136L, 137L, 138L, 143L, 144L, 145L, 146L, 147L, 148L,
149L, 150L, 151L, 152L, 153L, 154L, 155L, 158L, 159L, 160L, 161L,
162L, 163L, 164L, 165L, 169L, 170L, 171L, 172L, 177L, 178L, 179L,
180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L,
191L, 192L, 193L, 194L, 195L, 196L, 200L), Date_observed = structure(c(4L,
15L, 6L, 6L, 6L, 6L, 2L, 2L, 8L, 8L, 8L, 8L, 8L, 8L, 6L, 6L,
6L, 6L, 6L, 6L, 11L, 11L, 11L, 11L, 12L, 7L, 7L, 9L, 9L, 9L,
9L, 5L, 5L, 5L, 5L, 14L, 14L, 14L, 14L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 6L, 6L, 5L, 5L, 9L, 9L, 9L, 9L, 3L, 3L, 3L, 3L, 4L, 4L,
1L, 1L, 11L, 6L, 6L, 6L, 6L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 3L, 3L, 3L, 3L, 11L,
11L, 11L, 4L, 4L, 4L, 4L, 8L, 8L, 10L, 10L, 10L, 10L, 9L, 9L,
9L, 9L, 3L, 3L, 3L, 3L, 9L, 9L, 9L, 9L, 2L, 2L, 2L, 2L, 13L,
13L, 13L, 13L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 3L, 3L, 3L,
3L, 13L), .Label = c("10/1/18", "10/19/18", "10/20/18", "10/21/18",
"10/22/18", "10/23/18", "10/24/18", "10/25/18", "10/26/18", "10/27/18",
"10/28/18", "10/28/19", "10/29/18", "12/9/18", "8/20/18"), class = "factor"),
Latitude = c(51.4175, 52.12087, 52.0269, 52.0269, 52.0269,
52.0269, 52.947709, 52.947709, 51.491811, 51.491811, 52.59925,
52.59925, 52.59925, 52.59925, 51.60157, 51.60157, 52.6888,
52.6888, 52.6888, 52.6888, 50.697802, 50.697802, 50.697802,
50.697802, 53.62417, 50.446841, 50.446841, 53.959679, 53.959679,
53.959679, 53.959679, 51.78375, 51.78375, 51.78375, 51.78375,
51.456965, 51.456965, 51.456965, 51.456965, 51.3651, 51.3651,
51.3651, 51.3651, 52.01182, 52.01182, 52.01182, 52.01182,
50.114277, 50.114277, 51.43474, 51.43474, 51.10676, 51.10676,
51.10676, 51.10676, 50.435984, 50.435984, 50.435984, 50.435984,
51.78666, 51.78666, 52.441088, 52.441088, 52.552344, 49.259471,
49.259471, 49.259471, 49.259471, 50.461625, 50.461625, 50.461625,
50.461625, 51.746642, 51.746642, 51.746642, 51.746642, 52.2501,
52.2501, 52.2501, 52.2501, 52.423336, 52.423336, 52.423336,
52.423336, 53.615575, 53.615575, 53.615575, 53.615575, 51.08474,
51.08474, 51.08474, 53.19329, 53.19329, 53.19329, 53.19329,
55.96785, 55.96785, 56.52664, 56.52664, 56.52664, 56.52664,
51.8113, 51.8113, 51.8113, 51.8113, 52.580157, 52.580157,
52.580157, 52.580157, 50.52008, 50.52008, 50.52008, 50.52008,
51.48417, 51.48417, 51.48417, 51.48417, 54.58243, 54.58243,
54.58243, 54.58243, 52.58839, 52.58839, 52.58839, 52.58839,
52.717283, 52.717283, 52.717283, 52.717283, 50.740764, 50.740764,
50.740764, 50.740764, 52.57937), Longitude = c(-0.32118,
-0.29293, -0.7078, -0.7078, -0.7078, -0.7078, -1.435407,
-1.435407, -3.210324, -3.210324, 1.33011, 1.33011, 1.33011,
1.33011, -3.67111, -3.67111, -3.30909, -3.30909, -3.30909,
-3.30909, -2.11692, -2.11692, -2.11692, -2.11692, -2.43155,
-3.706923, -3.706923, -1.061008, -1.061008, -1.061008, -1.061008,
-0.65046, -0.65046, -0.65046, -0.65046, -2.624917, -2.624917,
-2.624917, -2.624917, 0.70706, 0.70706, 0.70706, 0.70706,
-0.70082, -0.70082, -0.70082, -0.70082, -5.541128, -5.541128,
0.45981, 0.45981, -2.32071, -2.32071, -2.32071, -2.32071,
-4.105617, -4.105617, -4.105617, -4.105617, -0.71433, -0.71433,
-0.176158, -0.176158, -1.337177, -123.107788, -123.107788,
-123.107788, -123.107788, 3.560973, 3.560973, 3.560973, 3.560973,
0.486416, 0.486416, 0.486416, 0.486416, -0.8825, -0.8825,
-0.8825, -0.8825, -1.787563, -1.787563, -1.787563, -1.787563,
-2.432959, -2.432959, -2.432959, -2.432959, -0.73645, -0.73645,
-0.73645, -0.63793, -0.63793, -0.63793, -0.63793, -3.18084,
-3.18084, -3.40313, -3.40313, -3.40313, -3.40313, -0.22894,
-0.22894, -0.22894, -0.22894, -1.948571, -1.948571, -1.948571,
-1.948571, -4.20756, -4.20756, -4.20756, -4.20756, -0.34854,
-0.34854, -0.34854, -0.34854, -5.93229, -5.93229, -5.93229,
-5.93229, -1.96843, -1.96843, -1.96843, -1.96843, -2.410575,
-2.410575, -2.410575, -2.410575, -2.361234, -2.361234, -2.361234,
-2.361234, -1.89325), Altitude = c(5L, 0L, 68L, 68L, 68L,
68L, 104L, 104L, 15L, 15L, 23L, 23L, 23L, 23L, 184L, 184L,
176L, 176L, 176L, 176L, 12L, 12L, 12L, 12L, 178L, 36L, 36L,
11L, 11L, 11L, 11L, 210L, 210L, 210L, 210L, 97L, 97L, 97L,
97L, 23L, 23L, 23L, 23L, 0L, 0L, 0L, 0L, 9L, 9L, 4L, 4L,
200L, 200L, 200L, 200L, 160L, 160L, 160L, 160L, 166L, 166L,
0L, 0L, 0L, 47L, 47L, 47L, 47L, 58L, 58L, 58L, 58L, 43L,
43L, 43L, 43L, 97L, 97L, 97L, 97L, 133L, 133L, 133L, 133L,
123L, 123L, 123L, 123L, 128L, 128L, 128L, 15L, 15L, 15L,
15L, 14L, 14L, 65L, 65L, 65L, 65L, 129L, 129L, 129L, 129L,
140L, 140L, 140L, 140L, 18L, 18L, 18L, 18L, 30L, 30L, 30L,
30L, 19L, 19L, 19L, 19L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
96L, 96L, 96L, 96L, 169L), Species = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Quercus robur", class = "factor"),
Tree_diameter = c(68.8, 10, 98.5, 97, 32.5, 45.1, 847, 817,
62, 71, 140, 111.4, 114.6, 167.1, 29, 40.1, 68, 45, 60, 54,
104, 122, 85, 71, 81, 39.8, 43.6, 20.1, 17.8, 15.6, 12.1,
81.8, 102.5, 75.5, 57.3, 0.3, 0.2, 0.3, 0.3, 70, 36, 53,
44, 31.5, 27.1, 23.3, 22, 69.4, 37.3, 19.9, 14.6, 196, 122,
118, 180, 58.6, 54.1, 58, 61.5, 58.4, 61, 134, 64, 52.2,
170, 114, 127, 158, 147.4, 135.3, 122.9, 104.1, 263, 237,
322, 302, 175, 182, 141, 155, 89, 41, 70, 83, 141, 86.5,
82, 114.5, 129, 127, 143, 125, 92, 68, 90, 24.5, 20.1, 63.7,
39.8, 66.2, 112.4, 124.5, 94.1, 68.6, 74.4, 23.6, 27.7, 22.9,
25.2, 24.2, 54.7, 43, 33.1, 306, 274, 56, 60, 72.5, 128.5,
22, 16, 143, 103, 53, 130, 48.4, 69.8, 6.4, 18.6, 129.2,
41.7, 57.6, 14, 41.7), Urbanisation_index = c(2L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 1L, 1L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L), Stand_density_index = c(3L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 4L, 1L, 1L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 2L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 3L,
4L, 4L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L,
2L, 2L, 2L, 2L, 2L, 3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 2L, 4L, 4L, 4L, 4L, 4L), Canopy_Index = c(85L,
85L, 85L, 75L, 45L, 25L, 75L, 65L, 75L, 75L, 95L, 95L, 95L,
95L, 95L, 65L, 85L, 65L, 95L, 85L, 85L, 85L, 75L, 75L, 65L,
85L, 85L, 75L, 75L, 85L, 65L, 95L, 85L, 95L, 95L, 75L, 75L,
85L, 85L, 85L, 85L, 85L, 75L, 85L, 85L, 85L, 85L, 75L, 75L,
85L, 85L, 65L, 75L, 85L, 75L, 95L, 95L, 95L, 95L, 75L, 65L,
95L, 95L, 55L, 75L, 65L, 75L, 65L, 85L, 95L, 95L, 75L, 95L,
75L, 95L, 65L, 75L, 75L, 85L, 85L, 65L, 95L, 65L, 65L, 65L,
65L, 65L, 65L, 85L, 85L, 75L, 95L, 85L, 85L, 75L, 45L, 55L,
35L, 35L, 25L, 25L, 95L, 85L, 75L, 85L, 85L, 75L, 75L, 65L,
75L, 85L, 65L, 45L, 95L, 95L, 95L, 95L, 65L, 75L, 45L, 35L,
75L, 95L, 95L, 85L, 75L, 65L, 85L, 95L, 75L, 85L, 85L, 95L,
65L), Phenological_Index = c(2L, 4L, 2L, 2L, 4L, 4L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 2L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 1L, 1L, 1L, 1L, 3L, 2L, 3L, 3L, 3L, 3L, 4L, 3L, 2L, 3L,
2L, 2L, 2L, 1L, 3L, 1L, 4L)), class = "data.frame", row.names = c(NA,
-134L))
Data frame - QuercusRobur2
structure(list(X = c(1L, 2L, 3L, 4L, 13L, 14L, 15L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 35L, 36L,
37L, 38L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
59L, 63L, 64L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L,
78L, 80L, 89L, 90L, 91L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 118L, 119L, 120L, 121L, 126L, 127L, 128L, 129L, 130L,
131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 141L, 142L, 143L,
144L, 148L, 149L, 150L, 151L, 156L, 157L, 158L, 159L, 160L, 161L,
162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L,
173L, 174L, 175L, 179L, 180L, 181L, 182L, 183L, 185L, 187L, 189L,
190L, 191L, 192L, 193L, 194L, 195L, 196L, 208L, 209L, 210L, 212L,
214L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 242L, 243L, 244L,
245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L, 255L,
256L, 257L, 258L, 259L, 260L, 261L), Obs_no = c(1L, 2L, 3L, 4L,
13L, 14L, 15L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 35L, 36L, 37L, 38L, 48L, 49L, 50L, 51L, 52L, 53L,
54L, 55L, 56L, 57L, 58L, 59L, 63L, 64L, 68L, 69L, 70L, 71L, 72L,
73L, 74L, 75L, 76L, 77L, 78L, 80L, 89L, 90L, 91L, 95L, 96L, 97L,
98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L,
109L, 110L, 111L, 112L, 113L, 114L, 118L, 119L, 120L, 121L, 126L,
127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L,
138L, 141L, 142L, 143L, 144L, 148L, 149L, 150L, 151L, 156L, 157L,
158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L,
169L, 170L, 171L, 172L, 173L, 174L, 175L, 179L, 180L, 181L, 182L,
183L, 185L, 187L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L,
208L, 209L, 210L, 212L, 214L, 225L, 226L, 227L, 228L, 229L, 230L,
231L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L,
252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L),
Date_observed = structure(c(9L, 14L, 3L, 3L, 12L, 12L, 10L,
10L, 8L, 8L, 8L, 8L, 11L, 11L, 11L, 11L, 5L, 5L, 9L, 9L,
13L, 13L, 13L, 13L, 8L, 8L, 8L, 8L, 13L, 13L, 13L, 13L, 7L,
7L, 7L, 7L, 6L, 6L, 11L, 11L, 11L, 11L, 11L, 11L, 4L, 4L,
4L, 4L, 12L, 12L, 12L, 12L, 5L, 1L, 1L, 1L, 1L, 5L, 5L, 5L,
5L, 12L, 12L, 12L, 12L, 11L, 11L, 11L, 11L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 13L, 13L, 13L, 8L, 8L, 8L, 8L, 13L, 13L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
3L, 3L, 3L, 3L, 13L, 13L, 13L, 13L, 10L, 10L, 10L, 10L, 12L,
12L, 12L, 12L, 3L, 3L, 3L, 3L, 13L, 13L, 5L, 5L, 5L, 11L,
11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
9L, 9L, 12L, 12L, 12L, 12L, 8L, 8L, 8L, 5L, 5L, 5L, 5L, 12L,
12L, 12L, 12L, 11L, 11L, 11L, 11L, 13L, 13L, 13L, 13L, 5L,
5L, 5L, 5L), .Label = c("10/23/18", "11/18/18", "11/30/18",
"12/1/18", "12/10/18", "12/12/18", "12/2/18", "12/3/18",
"12/4/18", "12/6/18", "12/7/18", "12/8/18", "12/9/18", "9/10/18"
), class = "factor"), Latitude = c(51.41752, 52.243806, 52.947709,
52.947709, 51.491811, 51.491811, 51.60157, 51.60157, 52.68959,
52.68959, 52.68959, 52.68959, 50.697802, 50.697802, 50.697802,
50.697802, 53.62417, 53.62417, 50.446841, 50.446841, 53.959679,
53.959679, 53.959679, 53.959679, 51.78375, 51.78375, 51.78375,
51.78375, 51.456965, 51.456965, 51.456965, 51.456965, 52.011812,
52.011812, 52.011812, 52.011812, 50.121978, 50.121978, 51.43474,
51.43474, 51.10708, 51.10708, 51.10708, 51.10708, 50.435984,
50.435984, 50.435984, 50.435984, 51.78666, 51.78666, 52.441088,
52.441088, 52.552344, 49.259471, 49.259471, 49.259471, 49.259471,
50.462, 50.462, 50.462, 50.462, 51.746642, 51.746642, 51.746642,
51.746642, 52.2501, 52.2501, 52.2501, 52.2501, 52.42646,
52.42646, 52.42646, 52.42646, 53.615575, 53.615575, 53.615575,
53.615575, 51.08478, 51.08478, 51.08478, 53.19329, 53.19329,
53.19329, 53.19329, 55.968437, 55.968437, 56.52664, 56.52664,
56.52664, 56.52664, 51.8113, 51.8113, 51.8113, 51.8113, 50.52008,
50.52008, 50.52008, 50.52008, 51.48417, 51.48417, 51.48417,
51.48417, 54.58243, 54.58243, 54.58243, 54.58243, 52.58839,
52.58839, 52.58839, 52.58839, 52.717283, 52.717283, 52.717283,
52.717283, 50.740764, 50.740764, 50.740764, 50.740764, 50.733412,
50.733412, 50.79926, 50.79926, 50.79926, 53.675788, 53.675788,
48.35079, 48.35079, 48.35079, 48.35079, 51.36445, 51.36445,
51.36445, 51.36445, 52.122402, 52.122402, 52.122402, 52.16104,
52.16104, 51.88468, 51.88468, 51.88468, 51.88468, 52.34015,
52.34015, 52.34015, 52.026042, 52.026042, 52.026042, 52.026042,
51.319032, 51.319032, 51.319032, 51.319032, 51.51365, 51.51365,
51.51365, 51.51365, 53.43202, 53.43202, 53.43202, 53.43202,
51.50797, 51.50797, 51.50797, 51.50797), Longitude = c(-0.32116,
1.30786, -1.435407, -1.435407, -3.210324, -3.210324, -3.67111,
-3.67111, -3.3081, -3.3081, -3.3081, -3.3081, -2.11692, -2.11692,
-2.11692, -2.11692, -2.43155, -2.43155, -3.706923, -3.706923,
-1.061008, -1.061008, -1.061008, -1.061008, -0.65046, -0.65046,
-0.65046, -0.65046, -2.624917, -2.624917, -2.624917, -2.624917,
-0.70082, -0.70082, -0.70082, -0.70082, -5.555169, -5.555169,
0.45981, 0.45981, -2.32027, -2.32027, -2.32027, -2.32027,
-4.105617, -4.105617, -4.105617, -4.105617, -0.71433, -0.71433,
-0.176158, -0.176158, -1.337177, -123.107788, -123.107788,
-123.107788, -123.107788, -3.5607, -3.5607, -3.5607, -3.5607,
0.486416, 0.486416, 0.486416, 0.486416, -0.8825, -0.8825,
-0.8825, -0.8825, -1.78771, -1.78771, -1.78771, -1.78771,
-2.432959, -2.432959, -2.432959, -2.432959, -0.73626, -0.73626,
-0.73626, -0.63793, -0.63793, -0.63793, -0.63793, -3.179732,
-3.179732, -3.40313, -3.40313, -3.40313, -3.40313, -0.22894,
-0.22894, -0.22894, -0.22894, -4.20756, -4.20756, -4.20756,
-4.20756, -0.34854, -0.34854, -0.34854, -0.34854, -5.93229,
-5.93229, -5.93229, -5.93229, -1.96843, -1.96843, -1.96843,
-1.96843, -2.410575, -2.410575, -2.410575, -2.410575, -2.361234,
-2.361234, -2.361234, -2.361234, -2.014029, -2.014029, -3.19446,
-3.19446, -3.19446, -1.272404, -1.272404, 10.91812, 10.91812,
10.91812, 10.91812, -0.23106, -0.23106, -0.23106, -0.23106,
-0.487443, -0.487443, -0.487443, 0.18702, 0.18702, -0.17853,
-0.17853, -0.17853, -0.17853, -1.27795, -1.27795, -1.27795,
-0.503113, -0.503113, -0.503113, -0.503113, -0.472994, -0.472994,
-0.472994, -0.472994, -3.18722, -3.18722, -3.18722, -3.18722,
-2.27968, -2.27968, -2.27968, -2.27968, -0.25931, -0.25931,
-0.25931, -0.25931), Altitude = c(0, 0, 103.9, 103.9, 15,
15, 184, 184, 176, 176, 176, 176, 12, 12, 12, 12, 178, 178,
36, 36, 11, 11, 11, 11, 210, 210, 210, 210, 97, 97, 97, 97,
0, 0, 0, 0, 68, 68, 4, 4, 200, 200, 200, 200, 160, 160, 160,
160, 165.8, 165.8, 0, 0, 0, 47, 47, 47, 47, 0, 0, 0, 0, 43,
43, 43, 43, 97, 97, 97, 97, 133, 133, 133, 133, 123, 123,
123, 123, 127, 127, 127, 15, 15, 15, 15, 14, 14, 65, 65,
65, 65, 129, 129, 129, 129, 18, 18, 18, 18, 30, 30, 30, 30,
19, 19, 19, 19, 0, 0, 0, 0, 0, 0, 0, 0, 96, 96, 96, 96, 0,
0, 0, 0, 0, 49, 49, 0, 0, 0, 0, 48, 48, 48, 48, 43, 43, 43,
75, 75, 94, 94, 94, 94, 112, 112, 112, 103, 103, 103, 103,
0, 0, 0, 0, 37.5, 37.5, 37.5, 37.5, 29, 29, 29, 29, 63, 63,
63, 63), Species = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Quercus robur", class = "factor"),
Tree_diameter = c(68.8, 300, 847, 817, 62, 71, 29, 40.1,
68, 45, 60, 54, 104, 122, 85, 71, 81, 118, 39.8, 43.6, 19.8,
16.6, 15.1, 11.9, 81.8, 102.5, 75.5, 57.3, 0.3, 0.2, 0.3,
0.3, 99, 85, 74, 68, 82, 51.8, 19.9, 14.6, 196, 122, 118,
180, 58.6, 54.1, 58, 61.5, 58.4, 61, 134, 64, 52.2, 170,
114, 127, 158, 147.4, 135.3, 122.9, 104.1, 263, 237, 322,
302, 173, 186, 144, 155, 89, 41, 68, 83, 141.6, 85.5, 82.8,
114.1, 129, 127, 143, 125, 92, 68, 90, 25, 20, 63.7, 39.8,
66.2, 112.4, 124.5, 94.1, 68.6, 74.4, 24.2, 54.7, 43, 33.1,
306, 274, 56, 60, 72.5, 128.5, 22, 16, 143, 103, 53, 130,
48.4, 69.8, 6.4, 18.6, 129.2, 41.7, 57.6, 14, 320, 352, 120.9,
108.3, 53.2, 274, 85, 52, 43, 38, 37, 219, 215, 216, 175,
85.9, 49.7, 97.1, 40.8, 62.4, 181.5, 149.7, 122, 143.6, 148,
145, 99, 27.5, 32, 54, 54.1, 169, 152, 160, 138, 90.8, 87.9,
77.4, 81.2, 91.7, 62.7, 50, 72.9, 24.8, 61, 88.6, 80.1),
Urbanisation_index = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L,
2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 1L, 1L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 4L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 1L, 1L, 1L,
1L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("1", "2",
"3", "4"), class = "factor"), Stand_density_.index = structure(c(3L,
4L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L,
4L, 4L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 4L, 4L, 3L, 3L,
3L, 3L, 4L, 3L, 4L, 4L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 3L, 4L, 4L, 4L, 4L, 2L,
2L, 2L, 2L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 2L,
2L, 2L, 2L, 4L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 2L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L), .Label = c("1",
"2", "3", "4"), class = "factor"), Canopy_Index = c(15L,
95L, 45L, 5L, 5L, 5L, 25L, 15L, 25L, 25L, 35L, 35L, 25L,
35L, 15L, 15L, 15L, 15L, 5L, 5L, 5L, 5L, 5L, 5L, 35L, 35L,
55L, 35L, 5L, 5L, 5L, 5L, 95L, 95L, 95L, 95L, 25L, 25L, 15L,
5L, 25L, 25L, 25L, 25L, 5L, 5L, 5L, 5L, 5L, 5L, 35L, 25L,
5L, 35L, 35L, 25L, 25L, 5L,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L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L)), row.names = c(NA, -165L), class = "data.frame")
How about using subtitle for labeling each individual plot?
## Observation 1
p1 <- ggplot(
QuercusRobur1,
aes(x = Longitude, y = Latitude)
) +
geom_polygon(
data = UK,
aes(x = long, y = lat, group = group),
inherit.aes = FALSE
) +
coord_map(xlim = c(-10, 5)) + # limits added as there are some points really far away
theme_classic()
Urban1 <- p1 +
geom_point(aes(color = factor(Urbanisation_index))) +
scale_color_discrete(
name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural")
) +
labs(subtitle = "A: Urbanisation Index") +
theme(legend.justification = "left")
Stand1 <- p1 +
geom_point(aes(color = factor(Stand_density_index))) +
scale_color_discrete(
name = "Stand Density Index",
labels = c(
"Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"
)
) +
labs(subtitle = "C: Stand Density Index") +
theme(legend.justification = "left")
## Observation 2
p2 <- ggplot(
QuercusRobur2,
aes(x = Longitude, y = Latitude)
) +
geom_polygon(
data = UK,
aes(x = long, y = lat, group = group),
inherit.aes = FALSE
) +
coord_map(xlim = c(-10, 5)) +
theme_classic()
Urban2 <- p2 +
geom_point(aes(color = factor(Urbanisation_index))) +
scale_color_discrete(
name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural")
) +
labs(subtitle = "B: Urbanisation Index") +
theme(legend.justification = "left")
Stand2 <- p2 +
geom_point(aes(color = factor(Stand_density_.index))) +
scale_color_discrete(
name = "Stand Density Index",
labels = c(
"Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"
)
) +
labs(subtitle = "D: Stand Density Index") +
theme(legend.justification = "left")
## Arrange the individual plots into one main plot
plot_grid(
Urban1 + ggtitle("Observational Period 1\n") + theme(plot.title = element_text(hjust = 1.0)),
Urban2 + ggtitle("Observational Period 2\n") + theme(plot.title = element_text(hjust = 1.0)),
Stand1,
Stand2,
align = "hv",
axis = 'tblr',
label_fontface = "bold",
label_fontfamily = "Times New Roman",
label_size = 8,
rel_widths = c(1, 1.3),
ncol = 2,
nrow = 2,
hjust = 0,
label_x = 0.01
)
Edit: remove duplicate axis labels and legends then use egg::ggarrange to combine subplots.
## Observation 1
Urban1 <- p1 +
geom_point(aes(color = factor(Urbanisation_index))) +
scale_color_discrete(
name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural")
) +
labs(subtitle = "A: Urbanisation Index") +
theme(legend.position = "none")
Stand1 <- p1 +
geom_point(aes(color = factor(Stand_density_index))) +
scale_color_discrete(
name = "Stand Density Index",
labels = c(
"Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"
)
) +
labs(subtitle = "C: Stand Density Index") +
theme(legend.position = "none")
## Observation 2
p2 <- ggplot(
QuercusRobur2,
aes(x = Longitude, y = Latitude)
) +
geom_polygon(
data = UK,
aes(x = long, y = lat, group = group),
inherit.aes = FALSE
) +
coord_map(xlim = c(-10, 5)) +
theme_classic() +
ylab("")
Urban2 <- p2 +
geom_point(aes(color = factor(Urbanisation_index))) +
scale_color_discrete(
name = "Urbanisation Index",
labels = c("Urban", "Suburban", "Village", "Rural")
) +
labs(subtitle = "B: Urbanisation Index") +
theme(legend.justification = "left")
Stand2 <- p2 +
geom_point(aes(color = factor(Stand_density_.index))) +
scale_color_discrete(
name = "Stand Density Index",
labels = c(
"Standing alone",
"Within a few trees or close proximity to other trees",
"Within a stand of 10-30 trees",
"Large or woodland"
)
) +
labs(subtitle = "D: Stand Density Index") +
theme(legend.justification = "left")
## Use the `egg` package
library(egg)
ggarrange(
Urban1 + ggtitle("Observational Period 1\n") + theme(plot.title = element_text(hjust = 0.5)),
Urban2 + ggtitle("Observational Period 2\n") + theme(plot.title = element_text(hjust = 0.5)),
Stand1,
Stand2,
nrow = 2,
ncol = 2
)

Trouble with GLMM with glmer in R: Error in pwrssUpdate...halvings failed to reduce deviance in pwrssUpdate

Here's a snipped of randomly selected data from my full dataframe:
canopy<-structure(list(Stage = structure(c(6L, 5L, 3L, 6L, 7L, 5L, 4L,
7L, 2L, 7L, 5L, 1L, 1L, 4L, 3L, 6L, 5L, 7L, 4L, 4L), .Label = c("milpa",
"robir", "jurup che", "pak che kor", "mehen che", "nu kux che",
"tam che"), class = c("ordered", "factor")), ID = c(44L, 34L,
18L, 64L, 54L, 59L, 28L, 51L, 11L, 56L, 33L, 1L, 7L, 25L, 58L,
48L, 36L, 51L, 27L, 66L), Sample = c(4L, 2L, 2L, 10L, 6L, 9L,
4L, 3L, 3L, 8L, 1L, 1L, 7L, 1L, 10L, 8L, 4L, 3L, 3L, 10L), Subsample = c(2L,
3L, 4L, 3L, 2L, 1L, 3L, 2L, 4L, 3L, 1L, 3L, 2L, 4L, 1L, 1L, 3L,
1L, 1L, 4L), Size..ha. = c(0.5, 0.5, 0.5, 0.5, 6, 0.5, 0.5, 0.25,
0.5, 6, 1, 1, 0.5, 2, 1, 0.5, 1, 0.25, 0.5, 2), Avg.Subsample.Canopy = c(94.8,
94.8, 97.92, 96.88, 97.14, 92.46, 93.24, 97.4, 25.64, 97.4, 94.8,
33.7, 13.42, 98.18, 85.44, 96.36, 97.4, 95.58, 85.7, 92.2), dec = c(0.948,
0.948, 0.9792, 0.9688, 0.9714, 0.9246, 0.9324, 0.974, 0.2564,
0.974, 0.948, 0.337, 0.1342, 0.9818, 0.8544, 0.9636, 0.974, 0.9558,
0.857, 0.922)), .Names = c("Stage", "ID", "Sample", "Subsample",
"Size..ha.", "Avg.Subsample.Canopy", "dec"), row.names = c(693L,
537L, 285L, 1017L, 853L, 929L, 441L, 805L, 173L, 889L, 513L,
9L, 101L, 397L, 913L, 753L, 569L, 801L, 417L, 1053L), class = "data.frame")
I am trying to code a GLMM of dec as a function of Stage and Size..ha.
The GLMM is necessary because each row represents a point Subsample measured within a larger Sample area. I am also using a binomial distribution given dec are proportional data.
I tried the model:
canopy.binomial.mod<-glmer(dec~Stage*Size..ha.+(1|Sample),family="binomial",data=canopy)
summary(canopy.binomial.mod)
but get the error:
Error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev
= compDev, : (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
I've seen online that this can be a result of needing to scale a predictor variable, so I tried:
cs. <- function(x) scale(x,scale=TRUE,center=TRUE)
canopy.binomial.mod<-glmer(dec~Stage*cs.(Size..ha.)+(1|Sample),family="binomial",data=canopy.rmna)
summary(canopy.binomial.mod)
Which doesn't seem to help. I also thought that maybe I'm asking too much of the model and it's not converging due to too many predictor variables, so let's remove the Size variable, which is of less interest to me.
canopy.binomial.mod<-glmer(dec~Stage+(1|Sample),family="binomial",data=canopy.rmna)
summary(canopy.binomial.mod)
Still no luck. Any ideas how to address this?

Resources