I would like to perform a cox regression analysis with value_max_min as predictor, but according 2 groups peakand drop in the column peak_drop_status(to get 2 survival curves).
cox <- coxph(Surv(mace_months_date_vs_date_sample, mace) ~ value_max_min, data = df)
and to get the plot
fit <- survfit(Surv(mace_months_date_vs_date_sample, mace) ~ value_max_min,
data = df)
I thought about using the group_by or the slice functions?
Library used:
library(dplyr)
library(survival)
library(survminer)
Here is the console output:
structure(list(ID = c(136L, 136L, 200L, 200L, 146L, 146L, 153L,
153L, 137L, 137L, 214L, 214L, 85L, 85L, 96L, 96L, 172L, 172L,
182L, 182L, 87L, 87L, 93L, 93L, 210L, 210L, 69L, 69L, 132L, 132L,
68L, 68L, 74L, 74L, 9L, 9L, 159L, 159L, 7L, 7L, 154L, 154L, 94L,
94L, 113L, 113L, 124L, 124L, 131L, 131L, 143L, 143L, 151L, 151L,
213L, 213L, 225L, 225L, 160L, 160L, 226L, 226L, 133L, 133L, 105L,
105L, 119L, 119L, 156L, 156L, 208L, 208L, 117L, 117L, 227L, 227L,
97L, 97L, 221L, 221L, 187L, 187L, 155L, 155L, 189L, 189L, 219L,
219L, 178L, 178L, 181L, 181L, 184L, 184L, 165L, 165L, 233L, 233L,
180L, 180L, 192L, 192L, 79L, 79L, 183L, 183L, 139L, 139L, 199L,
199L, 81L, 81L, 162L, 162L, 104L, 104L, 237L, 237L, 128L, 128L,
73L, 73L, 229L, 229L, 138L, 138L, 218L, 218L, 95L, 95L, 110L,
110L, 190L, 190L, 72L, 72L, 127L, 127L, 164L, 164L, 111L, 111L,
194L, 194L, 216L, 216L, 188L, 188L, 71L, 71L, 67L, 67L, 88L,
88L, 123L, 123L, 173L, 173L, 223L, 223L, 152L, 152L, 238L, 238L,
63L, 63L, 10L, 10L, 75L, 75L, 109L, 109L, 197L, 197L, 193L, 193L,
89L, 89L, 106L, 106L, 205L, 205L, 125L, 125L, 121L, 121L, 100L,
100L, 234L, 234L, 6L, 6L, 211L, 211L, 228L, 228L, 175L, 175L,
84L, 84L, 191L, 191L, 243L, 243L, 115L, 115L, 220L, 220L, 242L,
242L, 2L, 2L, 222L, 222L, 203L, 203L, 201L, 201L, 224L, 224L,
4L, 4L, 102L, 102L, 76L, 76L, 239L, 239L, 231L, 231L, 195L, 195L,
134L, 134L, 171L, 171L, 83L, 83L, 217L, 217L, 5L, 5L, 141L, 141L,
3L, 3L, 112L, 112L, 235L, 235L, 185L, 185L, 103L, 103L, 120L,
120L, 207L, 207L, 166L, 166L, 174L, 174L, 116L, 116L, 8L, 8L,
140L, 140L, 14L, 14L, 27L, 27L, 30L, 30L, 23L, 23L, 54L, 54L,
13L, 13L, 16L, 16L, 39L, 39L, 44L, 44L, 42L, 42L, 51L, 51L, 245L,
245L, 59L, 59L, 28L, 28L, 45L, 45L, 34L, 34L, 49L, 49L, 43L,
43L, 24L, 24L, 19L, 19L, 12L, 12L, 41L, 41L, 47L, 47L, 32L, 32L,
50L, 50L, 31L, 31L, 18L, 18L, 15L, 15L, 60L, 60L, 52L, 52L, 21L,
21L, 29L, 29L, 38L, 38L, 55L, 55L, 33L, 33L, 56L, 56L, 244L,
244L, 36L, 36L, 20L, 20L, 17L, 17L, 57L, 57L, 35L, 35L, 22L,
22L, 26L, 26L, 25L, 25L, 37L, 37L, 58L, 58L, 61L, 61L), age = c(49L,
49L, 77L, 77L, 75L, 75L, 75L, 75L, 63L, 63L, 60L, 60L, 72L, 72L,
51L, 51L, 50L, 50L, 35L, 35L, 48L, 48L, 44L, 44L, 79L, 79L, 67L,
67L, 57L, 57L, 58L, 58L, 46L, 46L, 57L, 57L, 59L, 59L, 71L, 71L,
65L, 65L, 56L, 56L, 28L, 28L, 65L, 65L, 41L, 41L, 76L, 76L, 63L,
63L, 66L, 66L, 69L, 69L, 37L, 37L, 52L, 52L, 47L, 47L, 63L, 63L,
41L, 41L, 79L, 79L, 42L, 42L, 69L, 69L, 76L, 76L, 68L, 68L, 66L,
66L, 59L, 59L, 64L, 64L, 72L, 72L, 65L, 65L, 75L, 75L, 56L, 56L,
80L, 80L, 68L, 68L, 58L, 58L, 61L, 61L, 59L, 59L, 68L, 68L, 60L,
60L, 39L, 39L, 63L, 63L, 52L, 52L, 82L, 82L, 63L, 63L, 49L, 49L,
59L, 59L, 61L, 61L, 64L, 64L, 63L, 63L, 66L, 66L, 68L, 68L, 54L,
54L, 73L, 73L, 54L, 54L, 46L, 46L, 75L, 75L, 72L, 72L, 64L, 64L,
69L, 69L, 68L, 68L, 59L, 59L, 52L, 52L, 65L, 65L, 51L, 51L, 48L,
48L, 63L, 63L, 52L, 52L, 56L, 56L, 67L, 67L, 68L, 68L, 47L, 47L,
75L, 75L, 76L, 76L, 63L, 63L, 73L, 73L, 48L, 48L, 68L, 68L, 48L,
48L, NA, NA, 74L, 74L, 37L, 37L, 60L, 60L, 54L, 54L, 55L, 55L,
61L, 61L, 79L, 79L, 67L, 67L, 57L, 57L, 51L, 51L, 67L, 67L, 68L,
68L, 51L, 51L, 53L, 53L, 51L, 51L, 62L, 62L, 60L, 60L, 71L, 71L,
58L, 58L, 52L, 52L, 72L, 72L, 73L, 73L, 76L, 76L, 81L, 81L, 48L,
48L, 65L, 65L, 57L, 57L, 51L, 51L, 56L, 56L, 66L, 66L, 46L, 46L,
78L, 78L, 76L, 76L, 81L, 81L, 71L, 71L, 46L, 46L, 51L, 51L, 73L,
73L, 66L, 66L, 59L, 59L, 77L, 77L, 74L, 74L, 28L, 28L, 73L, 73L,
54L, 54L, 59L, 59L, 53L, 53L, 57L, 57L, 54L, 54L, 52L, 52L, 38L,
38L, 73L, 73L, 62L, 62L, 61L, 61L, 76L, 76L, 51L, 51L, 51L, 51L,
54L, 54L, 59L, 59L, 47L, 47L, 66L, 66L, 57L, 57L, 57L, 57L, 62L,
62L, 66L, 66L, 54L, 54L, 47L, 47L, 56L, 56L, 65L, 65L, 72L, 72L,
49L, 49L, 46L, 46L, 73L, 73L, 55L, 55L, 47L, 47L, 59L, 59L, 43L,
43L, 62L, 62L, 64L, 64L, 56L, 56L, 44L, 44L, 58L, 58L,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, 46L, 46L, 43L, 43L, 61L, 61L,
3L, 3L, 4L, 4L, 62L, 62L, 60L, 60L, 49L, 49L, 48L, 48L, 43L,
43L, 46L, 46L, 45L, 45L, 62L, 62L, 4L, 4L, 61L, 61L, 47L,
47L, 62L, 62L, 5L, 5L, 48L, 48L, 59L, 59L, 32L, 32L, 59L,
59L, 4L, 4L, 63L, 63L, 8L, 8L, 4L, 4L, 49L, 49L, 1L, 1L,
7L, 7L, 45L, 45L, 45L, 45L, 1L, 1L, 1L, 1L, 62L, 62L, 62L,
62L, 45L, 45L, 1L, 1L, 61L, 61L, 46L, 46L, 55L, 55L, 44L,
44L, 45L, 45L, 1L, 1L, 58L, 58L, 27L, 27L, 47L, 47L, 48L,
48L, 25L, 25L, 55L, 55L, 50L, 50L, 44L, 44L, 63L, 63L, 50L,
50L, 10L, 10L, 23L, 23L, 47L, 47L, 19L, 19L, 48L, 48L, 62L,
62L, 62L, 62L, 1L, 1L, 15L, 15L, 47L, 47L, 61L, 61L, 45L,
45L, 46L, 46L, 47L, 47L, 49L, 49L, 1L, 1L, 46L, 46L, 48L,
48L, 45L, 45L, 15L, 15L, 55L, 55L, 1L, 1L, 62L, 62L, 55L,
55L, 46L, 46L, 2L, 2L, 46L, 46L, 46L, 46L, 63L, 63L, 43L,
43L, 16L, 16L, 55L, 55L, 1L, 1L, 55L, 55L, 8L, 8L, 46L, 46L,
46L, 46L, 19L, 19L, 48L, 48L, 50L, 50L, 48L, 48L, 41L, 41L,
50L, 50L, 4L, 4L, 62L, 62L, 62L, 62L, 17L, 17L, 25L, 25L,
48L, 48L, 48L, 48L, 3L, 3L, 1L, 1L, 53L, 53L, 46L, 46L, 46L,
46L, 51L, 51L, 59L, 59L, 55L, 55L, 59L, 59L, 55L, 55L, 1L,
1L, 46L, 46L, 43L, 43L, 1L, 1L, 5L, 5L, 46L, 46L, 10L, 10L,
11L, 11L, 16L, 16L, 55L, 55L, 3L, 3L, 6L, 6L, 71L, 71L, 68L,
68L, 72L, 72L, 71L, 71L, 69L, 69L, 73L, 73L, 74L, 74L, 30L,
30L, 69L, 69L, 1L, 1L, 11L, 11L, 79L, 79L, 71L, 71L, 73L,
73L, 13L, 13L, 28L, 28L, 74L, 74L, 77L, 77L, 78L, 78L, 71L,
71L, 73L, 73L, 69L, 69L, 73L, 73L, 70L, 70L, 72L, 72L, 69L,
69L, 43L, 43L, 76L, 76L, 74L, 74L, 75L, 75L, 77L, 77L, 78L,
78L, 70L, 70L, 69L, 69L, 70L, 70L, 60L, 60L, 5L, 5L, 5L,
5L, 77L, 77L, 74L, 74L, 77L, 77L, 77L, 77L, 77L, 77L, 73L,
73L, 74L, 74L, 76L, 76L, 76L, 76L), trop = c(262L, 262L,
NA, NA, 1454L, 1454L, 663L, 663L, 2107L, 2107L, 86115L, 86115L,
24L, 24L, 3004L, 3004L, 9352L, 9352L, NA, NA, 1247L, 1247L,
NA, NA, 2888L, 2888L, NA, NA, 8421L, 8421L, NA, NA, NA, NA,
251L, 251L, 1211L, 1211L, NA, NA, 54592L, 54592L, 1241L,
1241L, 8669L, 8669L, 5204L, 5204L, 751L, 751L, 2840L, 2840L,
250L, 250L, NA, NA, NA, NA, 1411L, 1411L, 3789L, 3789L, 1675L,
1675L, 1557L, 1557L, 440L, 440L, NA, NA, 6979L, 6979L, 6155L,
6155L, 5110L, 5110L, 87355L, 87355L, 90L, 90L, 2234L, 2234L,
10000L, 10000L, NA, NA, 843L, 843L, 950L, 950L, 372L, 372L,
NA, NA, NA, NA, NA, NA, 6212L, 6212L, 871L, 871L, 776L, 776L,
24160L, 24160L, NA, NA, 9951L, 9951L, 3598L, 3598L, 2040L,
2040L, NA, NA, 6581L, 6581L, 349L, 349L, 11L, 11L, 6694L,
6694L, 63L, 63L, 15543L, 15543L, NA, NA, 33017L, 33017L,
2483L, 2483L, NA, NA, 961L, 961L, 1470L, 1470L, 2380L, 2380L,
11135L, 11135L, 1730L, 1730L, NA, NA, 11450L, 11450L, 769L,
769L, 16720L, 16720L, 57L, 57L, NA, NA, 4281L, 4281L, NA,
NA, 1258L, 1258L, NA, NA, 4299L, 4299L, 13374L, 13374L, NA,
NA, 2844L, 2844L, 1753L, 1753L, NA, NA, 5256L, 5256L, 3624L,
3624L, NA, NA, 21876L, 21876L, 8903L, 8903L, 844L, 844L,
5654L, 5654L, 3569L, 3569L, 45649L, 45649L, NA, NA, NA, NA,
4927L, 4927L, NA, NA, 2177L, 2177L, 5247L, 5247L, 50000L,
50000L, 438L, 438L, 1480L, 1480L, 50L, 50L, NA, NA, NA, NA,
27L, 27L, 2956L, 2956L, NA, NA, 3000L, 3000L, NA, NA, 6630L,
6630L, 1911L, 1911L, NA, NA, 2797L, 2797L, 6672L, 6672L,
1627L, 1627L, 123L, 123L, 7671L, 7671L, NA, NA, NA, NA, 2340L,
2340L, 10014L, 10014L, 7860L, 7860L, 67927L, 67927L, NA,
NA, NA, NA, 2413L, 2413L, 1035L, 1035L, 40273L, 40273L, 7120L,
7120L, 6440L, 6440L, 3340L, 3340L, 8450L, 8450L, 1500L, 1500L,
1970L, 1970L, 180L, 180L, 990L, 990L, 2600L, 2600L, 1800L,
1800L, 5280L, 5280L, 83L, 83L, 160L, 160L, 40L, 40L, 3710L,
3710L, 400L, 400L, NA, NA, 2100L, 2100L, 2390L, 2390L, 9320L,
9320L, 6020L, 6020L, 320L, 320L, 1420L, 1420L, 1710L, 1710L,
15300L, 15300L, 6490L, 6490L, 6390L, 6390L, 6300L, 6300L,
470L, 470L, 1740L, 1740L, 3600L, 3600L, NA, NA, 3930L, 3930L,
NA, NA, 2260L, 2260L, 1360L, 1360L, 846L, 846L, 15940L, 15940L,
NA, NA, 840L, 840L, 5010L, 5010L, NA, NA, 5330L, 5330L, 500L,
500L, 1080L, 1080L, NA, NA, NA, NA, 4470L, 4470L), egfr = c(90L,
90L, 48L, 48L, 65L, 65L, 35L, 35L, 84L, 84L, 90L, 90L, 64L,
64L, 61L, 61L, 86L, 86L, 56L, 56L, 90L, 90L, 62L, 62L, 75L,
75L, 56L, 56L, 86L, 86L, 90L, 90L, 89L, 89L, 84L, 84L, 86L,
86L, 65L, 65L, 86L, 86L, 61L, 61L, 90L, 90L, 73L, 73L, 61L,
61L, 77L, 77L, 60L, 60L, 58L, 58L, 80L, 80L, 58L, 58L, 90L,
90L, 64L, 64L, 68L, 68L, 90L, 90L, 61L, 61L, 80L, 80L, 90L,
90L, 36L, 36L, 90L, 90L, 90L, 90L, 59L, 59L, 90L, 90L, 77L,
77L, 64L, 64L, 52L, 52L, 90L, 90L, 33L, 33L, 90L, 90L, 90L,
90L, 90L, 90L, 90L, 90L, 90L, 90L, 69L, 69L, 90L, 90L, 46L,
46L, 90L, 90L, 75L, 75L, 54L, 54L, 90L, 90L, 54L, 54L, 90L,
90L, 82L, 82L, 49L, 49L, 35L, 35L, 90L, 90L, 66L, 66L, 90L,
90L, 86L, 86L, 90L, 90L, 45L, 45L, 72L, 72L, 68L, 68L, 51L,
51L, 90L, 90L, 90L, 90L, 90L, 90L, 58L, 58L, 84L, 84L, 42L,
42L, 90L, 90L, 86L, 86L, 90L, 90L, 90L, 90L, 90L, 90L, 87L,
87L, 67L, 67L, 51L, 51L, 81L, 81L, 74L, 74L, 63L, 63L, 90L,
90L, 56L, 56L, 87L, 87L, 84L, 84L, 78L, 78L, 63L, 63L, 63L,
63L, 63L, 63L, 67L, 67L, 64L, 64L, 68L, 68L, 78L, 78L, 68L,
68L, 90L, 90L, 69L, 69L, 90L, 90L, 90L, 90L, 75L, 75L, 85L,
85L, 85L, 85L, 52L, 52L, 69L, 69L, 90L, 90L, 76L, 76L, 90L,
90L, 54L, 54L, 86L, 86L, 90L, 90L, 61L, 61L, 72L, 72L, 76L,
76L, 69L, 69L, 85L, 85L, 86L, 86L, 42L, 42L, 72L, 72L, 71L,
71L, 58L, 58L, 68L, 68L, 86L, 86L, 75L, 75L, 84L, 84L, 63L,
63L, 63L, 63L, 78L, 78L, 90L, 90L, 48L, 48L, 55L, 55L, 81L,
81L, 87L, 87L, 99L, 99L,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, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L), peak_drop_status = c("max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val", "max_val", "min_val", "max_val", "min_val", "max_val",
"min_val"), value_max_min = c(NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 308.408676147461, -283.636077880859,
NA, NA, 208.791275024414, -5.3211898803711, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, -14.9628820419311, -218.279922485352, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, -15.319938659668,
-279.422790527344, 248.09851074219, -30.822647094727, 116.716430664065,
-8.8325366973877, NA, NA, 10.0856704711914, -29.1057052612305,
179.8525390625, -10.1883692741394, 130.585632324218, -39.6044845581057,
32.883270263672, -5.3593330383301, -17.5934886932374, -821.989379882808,
375.086456298828, -5.7297992706299, NA, NA, NA, NA, NA, NA,
419.108337402341, -1.28273773193359, 55.87646484375, -17.770830154419,
NA, NA, 44.05969238281, -6.7603330612182, 36.9793767929077,
-58.77816772461, 47.6982421875, -48.2563076019287, 180.041305541992,
-3.5863590240479, 19.503479003907, -66.49755859375, NA, NA,
33.036499023438, -3.0688781738281, 83.0613746643061, -562.289733886719,
-5.5973930358887, -162.939453124998, 18.5003929138184, -95.700927734375,
164.985534667969, 9.7361946105957, 27.7907447814941, -69.5900268554681,
159.863708496094, -22.477741241455, -21.2021789550781, -372.002563476562,
153.190795898438, 5.9852733612061, 15.9482421875, -32.590072631836,
243.90209960937, -24.0595645904541, 131.392028808594, -5.5808029174805,
192.978088378906, -56.510217666626, 104.543823242188, -173.209777832031,
NA, NA, 174.83570098877, -69.742797851558, 12.743041992187,
-502.216308593755, 28.5669360160827, -388.549621582031, -15.8679084777832,
-308.033813476562, -12.657926082611, -133.534645795822, -0.800338745117202,
-170.645233154297, -8.9742355346679, -44.6486473083496, 3.6423645019532,
-0.407896041870121, 163.853607177735, -13.0253372192383,
327.035522460937, -3.5568542480469, 336.011077880859, -9.2046012878418
)), row.names = c(NA, -364L), class = c("tbl_df", "tbl",
"data.frame"))
Thank you,
To do a stratified Cox model, you would specify strata(var) in your model formula as follows:
library("survival")
library("survminer")
library("dplyr")
cox <- coxph(
Surv(mace_months_date_vs_date_sample, mace) ~ value_max_min + strata(peak_drop_status),
data = df
)
Your survfit isn't going to be very useful by the way, as you're supplying a numeric variable it's fitting a KM curve to every unique value of value_max_min. So you get a whole bunch of non-informative Kaplan-Meier curves:
fit <- survfit(
Surv(mace_months_date_vs_date_sample, mace) ~ value_max_min,
data = df
)
plot(fit)
It might be better for visualisation purposes to split your data into groups based on quantiles of the predictor:
med <- median(df$value_max_min, na.rm=TRUE)
fit <- survfit(
Surv(mace_months_date_vs_date_sample, mace) ~ (value_max_min > med),
data = df
)
plot(fit)
Related
I want learn Non-matric multidimensional scale, I have these data downloaded from https://cougrstats.wordpress.com/2019/12/11/non-metric-multidimensional-scaling-nmds-in-r/
data are
library(vegan)
dput(orders)
structure(list(Amphipoda = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 39L, 0L, 0L, 0L, 0L, 0L,
8L, 10L, 52L, 11L, 51L, 14L, 96L, 7L, 93L, 0L, 29L, 4L, 0L, 0L,
0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 36L, 10L, 5L, 15L, 14L, 3L, 11L,
6L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 2L, 4L, 4L, 3L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 54L, 51L, 47L, 212L,
26L, 51L, 0L, 0L, 4L, 0L, 0L, 0L, 4L, 6L, 14L, 34L, 8L, 284L,
1L, 2L, 6L, 92L, 134L, 98L, 38L, 8L, 116L, 0L, 0L, 8L, 264L,
104L, 114L, 138L, 152L, 42L, 46L, 10L, 67L, 25L, 0L, 0L, 1L,
12L, 0L, 26L, 0L, 67L, 456L, 7L, 2L, 46L, 155L, 82L, 124L, 596L,
0L, 36L, 1L, 1L, 588L, 0L, 0L, 16L, 0L, 0L, 470L, 0L, 6L, 262L,
2L, 476L, 0L, 6L, 14L, 0L, 342L, 0L, 6L, 4L, 24L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 74L, 170L, 37L, 228L, 144L, 21L, 189L, 117L, 45L, 132L, 108L,
35L, 0L, 0L, 0L, 0L, 0L, 0L), Coleoptera = c(42L, 5L, 7L, 14L,
2L, 43L, 7L, 2L, 15L, 5L, 6L, 23L, 25L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 0L, 2L, 0L, 1L, 0L, 0L, 0L, 142L, 96L, 202L, 306L,
917L, 748L, 139L, 148L, 115L, 216L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 12L, 36L, 48L, 30L, 10L, 12L, 11L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L,
0L, 0L, 381L, 397L, 229L, 51L, 266L, 102L, 201L, 189L, 80L, 292L,
271L, 583L, 641L, 318L, 729L, 520L, 582L, 262L, 59L, 209L, 134L,
139L, 108L, 79L, 99L, 96L, 13L, 60L, 22L, 15L, 27L, 1L, 11L,
2L, 3L, 3L, 6L, 1L, 1L, 0L, 20L, 48L, 129L, 82L, 16L, 70L, 114L,
77L, 190L, 27L, 163L, 125L, 244L, 43L, 70L, 88L, 202L, 52L, 39L,
70L, 10L, 5L, 26L, 108L, 37L, 38L, 81L, 5L, 52L, 14L, 33L, 0L,
26L, 12L, 41L, 3L, 5L, 15L, 1L, 10L, 18L, 31L, 40L, 22L, 23L,
21L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 4L, 17L, 7L, 59L, 21L, 0L, 84L,
41L, 95L, 83L, 52L, 100L, 90L, 34L, 31L, 19L, 27L, 51L, 62L,
7L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 4L, 6L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 6L, 0L, 6L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L,
0L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 29L, 68L, 119L, 156L,
114L, 73L, 81L, 115L, 5L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 4L, 131L, 135L, 102L, 219L, 165L, 207L, 149L, 105L, 147L,
195L, 332L, 316L, 22L, 55L, 17L, 12L, 50L, 49L), Diptera = c(210L,
54L, 336L, 80L, 210L, 647L, 171L, 948L, 1495L, 751L, 877L, 912L,
1130L, 170L, 105L, 72L, 26L, 190L, 138L, 91L, 46L, 96L, 39L,
49L, 66L, 87L, 82L, 69L, 29L, 548L, 1240L, 810L, 999L, 521L,
784L, 504L, 800L, 1190L, 360L, 539L, 331L, 742L, 1041L, 742L,
154L, 787L, 479L, 411L, 1181L, 1350L, 1423L, 747L, 1827L, 1758L,
2L, 172L, 1L, 278L, 145L, 250L, 121L, 294L, 121L, 219L, 254L,
278L, 305L, 269L, 212L, 248L, 229L, 229L, 225L, 311L, 236L, 209L,
257L, 226L, 655L, 440L, 416L, 39L, 398L, 323L, 461L, 670L, 934L,
401L, 686L, 619L, 1043L, 1578L, 767L, 432L, 1754L, 1228L, 2164L,
585L, 1336L, 933L, 928L, 454L, 833L, 928L, 745L, 604L, 69L, 1052L,
1228L, 15L, 1835L, 1459L, 1408L, 170L, 1367L, 146L, 14L, 164L,
101L, 780L, 779L, 259L, 537L, 576L, 480L, 1076L, 577L, 119L,
58L, 853L, 529L, 724L, 1329L, 381L, 194L, 428L, 1240L, 1349L,
29L, 42L, 249L, 881L, 1122L, 456L, 837L, 162L, 751L, 281L, 421L,
36L, 803L, 553L, 562L, 1769L, 151L, 1019L, 34L, 158L, 736L, 472L,
254L, 666L, 853L, 1175L, 795L, 1627L, 1229L, 960L, 1659L, 1719L,
713L, 0L, 5L, 216L, 199L, 335L, 64L, 466L, 98L, 1385L, 1162L,
1545L, 1457L, 1215L, 614L, 1247L, 1697L, 620L, 895L, 1297L, 902L,
12L, 264L, 76L, 4L, 2L, 36L, 44L, 2L, 326L, 6L, 66L, 9L, 70L,
13L, 2L, 8L, 0L, 0L, 11L, 42L, 2L, 2L, 4L, 2L, 70L, 4L, 120L,
138L, 126L, 14L, 1L, 93L, 10L, 40L, 3L, 15L, 186L, 54L, 304L,
12L, 34L, 34L, 8L, 296L, 80L, 50L, 36L, 0L, 0L, 10L, 40L, 4L,
0L, 0L, 98L, 68L, 2L, 0L, 7L, 8L, 6L, 186L, 148L, 0L, 6L, 14L,
106L, 0L, 0L, 2L, 2L, 62L, 4L, 4L, 318L, 742L, 1099L, 298L, 553L,
867L, 716L, 556L, 91L, 154L, 89L, 16L, 114L, 21L, 49L, 130L,
46L, 94L, 58L, 349L, 967L, 828L, 857L, 765L, 847L, 459L, 725L,
731L, 409L, 432L, 805L, 565L, 967L, 953L, 1398L, 999L, 1081L,
1104L), Ephemeroptera = c(27L, 9L, 2L, 1L, 0L, 38L, 11L, 4L,
234L, 3L, 1L, 218L, 44L, 0L, 0L, 0L, 0L, 1L, 8L, 1L, 2L, 3L,
23L, 5L, 7L, 6L, 8L, 3L, 3L, 173L, 718L, 1264L, 825L, 464L, 478L,
456L, 816L, 481L, 811L, 652L, 146L, 686L, 563L, 372L, 190L, 419L,
158L, 63L, 244L, 141L, 267L, 236L, 100L, 99L, 0L, 0L, 0L, 10L,
3L, 1L, 0L, 3L, 0L, 14L, 9L, 0L, 5L, 5L, 1L, 29L, 21L, 0L, 45L,
29L, 1L, 14L, 9L, 1L, 134L, 300L, 15L, 46L, 170L, 272L, 100L,
325L, 146L, 436L, 544L, 27L, 9L, 40L, 41L, 103L, 63L, 84L, 103L,
629L, 133L, 584L, 74L, 25L, 191L, 489L, 212L, 304L, 118L, 78L,
76L, 0L, 20L, 238L, 373L, 4L, 69L, 3L, 0L, 0L, 121L, 266L, 273L,
104L, 209L, 356L, 203L, 461L, 53L, 60L, 5L, 130L, 25L, 135L,
163L, 56L, 81L, 884L, 358L, 432L, 32L, 98L, 1L, 26L, 18L, 10L,
11L, 1L, 68L, 3L, 9L, 0L, 32L, 5L, 41L, 106L, 85L, 240L, 27L,
15L, 113L, 613L, 786L, 572L, 394L, 306L, 84L, 0L, 76L, 11L, 11L,
261L, 192L, 40L, 35L, 30L, 266L, 34L, 7L, 293L, 41L, 167L, 253L,
103L, 93L, 233L, 362L, 408L, 173L, 440L, 145L, 162L, 11L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 8L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 467L, 430L, 177L, 291L, 392L,
231L, 82L, 361L, 29L, 0L, 31L, 0L, 16L, 0L, 3L, 17L, 8L, 15L,
27L, 45L, 111L, 82L, 133L, 163L, 96L, 85L, 76L, 72L, 121L, 127L,
69L, 109L, 443L, 221L, 114L, 421L, 183L, 156L), Hemiptera = c(27L,
2L, 1L, 1L, 0L, 3L, 1L, 0L, 10L, 6L, 0L, 8L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 3L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0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L, 20L, 1L, 4L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Trichoptera = c(0L,
0L, 11L, 0L, 4L, 1L, 0L, 25L, 3L, 2L, 3L, 0L, 9L, 0L, 0L, 2L,
2L, 12L, 12L, 7L, 8L, 4L, 8L, 1L, 11L, 9L, 12L, 15L, 10L, 307L,
332L, 224L, 92L, 210L, 213L, 239L, 195L, 75L, 372L, 5L, 6L, 12L,
14L, 12L, 2L, 17L, 35L, 30L, 33L, 17L, 13L, 33L, 10L, 8L, 0L,
0L, 0L, 26L, 4L, 3L, 4L, 7L, 1L, 22L, 7L, 6L, 11L, 4L, 10L, 35L,
11L, 4L, 61L, 21L, 6L, 19L, 17L, 16L, 417L, 250L, 225L, 34L,
375L, 396L, 84L, 188L, 55L, 55L, 98L, 1145L, 713L, 342L, 2387L,
1404L, 908L, 685L, 44L, 692L, 691L, 101L, 35L, 14L, 296L, 145L,
44L, 274L, 62L, 31L, 49L, 1L, 135L, 24L, 219L, 2L, 60L, 6L, 0L,
0L, 120L, 31L, 126L, 68L, 62L, 182L, 153L, 27L, 61L, 31L, 51L,
153L, 185L, 190L, 174L, 372L, 170L, 81L, 180L, 218L, 3L, 22L,
5L, 161L, 23L, 10L, 54L, 1L, 22L, 11L, 17L, 0L, 19L, 12L, 74L,
13L, 29L, 64L, 1L, 1L, 1L, 193L, 561L, 97L, 112L, 241L, 19L,
9L, 14L, 16L, 5L, 5L, 5L, 71L, 22L, 75L, 239L, 44L, 16L, 346L,
31L, 169L, 353L, 120L, 117L, 187L, 361L, 210L, 28L, 181L, 53L,
19L, 3L, 0L, 0L, 0L, 0L, 3L, 0L, 10L, 26L, 4L, 0L, 18L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 20L, 0L, 0L, 0L, 22L, 11L, 8L, 10L, 4L,
0L, 0L, 5L, 2L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 8L,
4L, 13L, 0L, 0L, 2L, 0L, 4L, 0L, 1L, 0L, 0L, 0L, 4L, 0L, 0L,
0L, 0L, 0L, 24L, 0L, 0L, 0L, 2L, 0L, 1L, 0L, 0L, 2L, 0L, 0L,
107L, 230L, 52L, 14L, 46L, 44L, 29L, 85L, 7L, 0L, 11L, 0L, 2L,
0L, 0L, 5L, 3L, 4L, 0L, 7L, 90L, 97L, 166L, 243L, 160L, 62L,
122L, 72L, 297L, 139L, 102L, 145L, 40L, 19L, 16L, 12L, 3L, 7L
), Trombidiformes = c(6L, 1L, 59L, 1L, 4L, 16L, 3L, 1L, 3L, 2L,
2L, 49L, 12L, 0L, 0L, 0L, 1L, 2L, 3L, 8L, 1L, 8L, 10L, 11L, 0L,
15L, 1L, 5L, 8L, 31L, 31L, 59L, 48L, 111L, 155L, 153L, 116L,
102L, 210L, 4L, 3L, 2L, 2L, 4L, 0L, 6L, 5L, 52L, 215L, 76L, 107L,
103L, 116L, 100L, 0L, 0L, 0L, 0L, 0L, 2L, 3L, 0L, 0L, 1L, 0L,
2L, 1L, 0L, 2L, 1L, 0L, 4L, 1L, 5L, 10L, 3L, 0L, 1L, 5L, 19L,
7L, 5L, 13L, 7L, 8L, 2L, 2L, 6L, 0L, 1L, 0L, 0L, 0L, 3L, 1L,
2L, 0L, 0L, 0L, 50L, 21L, 22L, 41L, 26L, 4L, 70L, 2L, 8L, 16L,
0L, 48L, 35L, 6L, 3L, 16L, 6L, 2L, 0L, 7L, 8L, 43L, 17L, 9L,
26L, 32L, 24L, 52L, 16L, 39L, 34L, 26L, 29L, 6L, 51L, 53L, 75L,
198L, 93L, 49L, 29L, 37L, 59L, 92L, 45L, 66L, 4L, 38L, 33L, 36L,
2L, 116L, 31L, 70L, 9L, 32L, 8L, 2L, 8L, 8L, 80L, 92L, 51L, 187L,
75L, 130L, 143L, 128L, 83L, 80L, 67L, 76L, 0L, 2L, 1L, 47L, 14L,
0L, 105L, 14L, 52L, 50L, 54L, 20L, 54L, 48L, 34L, 6L, 47L, 23L,
10L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 16L, 2L, 8L, 0L, 13L, 8L, 0L, 0L, 29L, 12L, 2L, 2L, 3L, 1L,
0L, 44L, 23L, 1L, 12L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 0L, 0L, 0L, 8L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L,
36L, 0L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L,
23L, 93L, 26L, 257L, 61L, 36L, 179L, 56L, 20L, 0L, 61L, 0L, 66L,
0L, 3L, 0L, 3L, 0L, 0L, 27L, 66L, 76L, 113L, 44L, 30L, 15L, 16L,
18L, 23L, 39L, 95L, 41L, 37L, 28L, 45L, 22L, 21L, 9L), Tubificida = c(20L,
0L, 13L, 1L, 34L, 77L, 11L, 379L, 147L, 184L, 267L, 197L, 313L,
2L, 1L, 10L, 1L, 2L, 9L, 15L, 25L, 9L, 4L, 7L, 21L, 20L, 4L,
30L, 3L, 17L, 11L, 15L, 0L, 2L, 8L, 139L, 133L, 292L, 158L, 94L,
13L, 42L, 73L, 53L, 81L, 79L, 277L, 15L, 2L, 14L, 42L, 54L, 41L,
59L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 15L, 112L, 0L, 7L, 18L,
1L, 15L, 18L, 4L, 5L, 67L, 0L, 9L, 41L, 4L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 0L, 0L, 0L, 0L, 2L, 34L, 5L, 33L, 5L, 22L, 25L, 48L,
0L, 3L, 16L, 9L, 0L, 152L, 10L, 1L, 13L, 4L, 0L, 25L, 1L, 65L,
3L, 10L, 18L, 11L, 33L, 13L, 38L, 0L, 29L, 36L, 21L, 10L, 11L,
16L, 16L, 73L, 2L, 0L, 538L, 773L, 88L, 347L, 58L, 54L, 0L, 2L,
14L, 0L, 0L, 5L, 23L, 12L, 60L, 10L, 13L, 21L, 14L, 8L, 2L, 29L,
4L, 5L, 23L, 11L, 21L, 41L, 196L, 128L, 0L, 0L, 0L, 0L, 0L, 9L,
5L, 3L, 67L, 19L, 3L, 7L, 0L, 0L, 3L, 3L, 4L, 0L, 14L, 3L, 77L,
188L, 73L, 78L, 163L, 13L, 73L, 13L, 20L, 61L, 33L, 2L, 0L, 0L,
0L, 0L, 0L, 12L, 410L, 124L, 80L, 0L, 42L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 116L, 0L, 0L, 1L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 14L,
8L, 2L, 0L, 0L, 0L, 0L, 0L, 6L, 2L, 3L, 96L, 0L, 10L, 148L, 12L,
17L, 2L, 0L, 0L, 18L, 0L, 0L, 0L, 2L, 2L, 0L, 2L, 3L, 2L, 0L,
34L, 16L, 0L, 24L, 0L, 82L, 0L, 0L, 0L, 0L, 18L, 0L, 0L, 6L,
18L, 39L, 41L, 16L, 27L, 31L, 27L, 44L, 0L, 136L, 5L, 32L, 0L,
256L, 164L, 305L, 224L, 244L, 160L, 63L, 63L, 68L, 37L, 209L,
52L, 47L, 51L, 81L, 12L, 45L, 49L, 1L, 28L, 0L, 0L, 22L, 1L),
aquaticSiteType = c("stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream")), class = "data.frame", row.names = c(NA,
-303L))
I run the NMDS code using the code below
set.seed(1)
metaMDS(comm = orders[,1:8], # Define the community data
distance = "bray", # Specify a bray-curtis distance
try = 100) # Number of iterations
It worked properly, when i assign it to another object, there is no solution
set.seed(1)
nmds = metaMDS(comm = orders[,1:8], # Define the community data
distance = "bray", # Specify a bray-curtis distance
try = 100) # Number of iterations
Best solution was not repeated -- monoMDS stopping criteria:
2: no. of iterations >= maxit
16: stress ratio > sratmax
2: scale factor of the gradient < sfgrmin
why is this happenning? i also tried with several seeds and without seeds also, but the problem is the same.
and then when i tried the score value to data frame
data_scores = as.data.frame(scores(nmds))
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 303, 8
Why I am getting this error?
metaMDS worked OK and gave you results. No problem.
Your problem was that you assumed that scores gives you a simple matrix-like object that can be converted to a data.frame. It does not, but it gives you a list of sample scores and species scores:
> str(scores(nmds))
List of 2
$ sites : num [1:303, 1:2] -0.051 0.426 0.129 0.385 0.127 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:303] "1" "2" "3" "4" ...
.. ..$ : chr [1:2] "NMDS1" "NMDS2"
$ species: num [1:8, 1:2] -1.178 0.351 0.269 0.339 -1.177 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:8] "Amphipoda" "Coleoptera" "Diptera" "Ephemeroptera" ...
.. ..$ : chr [1:2] "NMDS1" "NMDS2"
You have two alternatives:
Request only one kind of scores. For instance this gives you only sample scores.
> str(scores(nmds, display="sites"))
num [1:303, 1:2] -0.051 0.426 0.129 0.385 0.127 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:303] "1" "2" "3" "4" ...
..$ : chr [1:2] "NMDS1" "NMDS2"
Request "tidy" scores that pack species and site scores in one data frame and add a variable that identifies the type of scores:
> str(scores(nmds, tidy=TRUE))
'data.frame': 311 obs. of 4 variables:
$ NMDS1: num -0.051 0.426 0.129 0.385 0.127 ...
$ NMDS2: num -0.2518 -0.1687 -0.0795 0.069 0.2453 ...
$ score: chr "sites" "sites" "sites" "sites" ...
$ label: chr "1" "2" "3" "4" ...
There are two issues here. The first is the notice that "best solution was not repeated" and the second is the error trying to coerce the scores to a data.frame.
As noted in the answer by Jari Oksanen, the latter error is a consequence of trying to force an object to be a data.frame when it has dimensions that do not allow it to be coerced to a data.frame.
However, the much bigger issue is that you should not trust the scores in the first place because the model has not converged. From the metaMDS documentation:
Non-linear optimization is a hard task, and the best possible solution
(“global optimum”) may not be found from a random starting
configuration. Most software solve this by starting from the result of
metric scaling (cmdscale). This will probably give a good result, but
not necessarily the “global optimum”. Vegan does the same, but metaMDS
tries to verify or improve this first solution (“try 0”) using several
random starts and seeing if the result can be repeated or improved and
the improved solution repeated. If this does not succeed, you get a
message that the result could not be repeated. However, the result
will be at least as good as the usual standard strategy of starting
from metric scaling or it may be improved. You may not need to do
anything after such a message, but you can be satisfied with the
result. If you want to be sure that you probably have a “global
optimum” you may try the following instructions.
That different starting points (a) produce a solution but (b) the solution differs based on initial starts means the optimizer has found a local solution that can be arbitrarily far from the global solution. In other words, the results you obtain can be arbitrarily wrong and shouldn't be trusted. In other software, this would throw and not provide you the results because it wouldn't trust you not to use the known-to-be-unreliable results.
For some reason, the authors of this don't do that but you should not let their decision to make this a warning instead of an error be a reason to ignore the fundamental issues with the results.
You can follow the steps discussed in the documentation linked above to address this.
At the moment, the legend is Quartile 4. HR 0.62 (95%CI 0.10-3.72), P=0.60.
I would like to create a condition when as follow: if P-value is >=0.95, I would like to write Quartile 4. P=0.99. So without the HR and the 95% CI.
HR and Ci make nonsense writing like this for now.
With this code:
#libraries
library(readxl)
library(tidyverse)
library(tidytidbits)
library(survivalAnalysis)
library(dplyr)
library(survival)
library(survminer)
library(ggplot2)
library(ggthemes)
library(ggpubr)
df$quantile <- df$delta_mon1_baseline_to_d3
#define quartile
df$Quartile <- findInterval(df$quantile, quantile(df$quantile, na.rm = TRUE)[-5])
#factor Quartile
df$Quartile <- factor(df$Quartile)
#cox regression
cox <- coxph(Surv(mace_months_date_vs_date_sample, mace) ~ Quartile, data = df)
# create the tags
coxP <- data.frame(summary(cox)$coefficients)[,5]
coxConf <- data.frame(summary(cox)$conf.int) %>%
rownames_to_column() %>%
mutate(p = coxP,
p2 = case_when( # determine direction
round(p, 3) > p ~ '=',
round(p, 3) < p ~ '=',
round(p, 3) == p ~ '='
),
p3 = ifelse(round(p, 2) == 1, T, F), # id if p value is 1 (too high!)
# gsub adds space, round, keep trailing zeros
tag = paste0(rowname %>% gsub("(\\D)(\\d)", "\\1 \\2", .),
". HR ", exp.coef. %>% sprintf(fmt = "%.2f", .),
" (95% CI ",
lower..95 %>% sprintf(fmt = "%.2f", .),
"-", upper..95 %>% sprintf(fmt = "%.2f", .),
"), P", p2, "",
ifelse(p3,
yes = "0.99", # if p rounded = 1
no = sprintf(fmt = "%.2f", p)))) %>%
select(tag)
# validate as expected
coxConf
I have got this legend in the graph
Here are my data:
ID age sex mace mace_months_date_vs_date_sample trop egfr dm smoke delta_mon1_baseline_to_d3
1 44 52 1 1 30 2600 56 1 0 -822.
2 32 66 1 0 73 1710 90 1 0 -562.
3 20 56 1 1 5 NA 75 0 1 -502.
4 17 44 1 0 77 840 71 0 0 -389.
5 52 49 1 0 74 1740 71 0 1 -372.
6 57 58 1 0 74 5010 68 0 1 -308.
7 79 68 1 0 45 776 90 0 0 -284.
8 14 74 1 1 6 7120 78 0 0 -279.
9 223 63 1 0 46 4281 90 0 0 -218.
10 56 43 1 0 70 1360 90 1 0 -173.
11 50 54 1 0 70 15300 90 0 1 -163.
12 31 47 0 0 72 6490 77 1 1 -95.7
13 35 47 1 0 77 NA 83 0 0 -71.0
14 36 64 1 1 5 15940 52 0 1 -69.7
15 15 65 1 1 43 6300 49 1 0 -69.6
16 12 57 1 0 71 6020 88 0 1 -66.5
17 43 59 0 0 74 2100 84 0 1 -58.8
18 22 46 1 0 77 5330 88 0 1 -29.3
19 54 59 1 0 71 1500 81 1 1 -25.7
20 26 66 1 0 77 500 51 0 0 -12.5
21 29 73 0 0 77 NA 51 0 0 -2.99
22 25 54 1 0 73 1080 87 0 0 2.81
23 39 54 1 0 74 990 77 0 0 32.9
24 47 62 1 0 69 1420 85 0 0 33.0
25 49 54 1 1 28 NA 76 1 0 44.1
26 24 47 1 0 77 2390 90 0 1 47.7
27 45 51 0 0 73 3710 65 0 1 55.9
28 30 73 0 0 68 3340 48 1 1 117.
29 16 57 1 0 73 180 99 0 1 131.
30 55 47 1 0 70 NA 90 0 1 131.
31 37 81 1 0 74 NA 99 1 1 147.
32 21 46 1 0 75 3600 87 0 1 153.
33 60 72 1 0 76 470 62 0 0 160.
34 18 56 1 0 69 6390 90 0 1 165.
35 13 53 1 0 69 1970 87 1 1 180.
36 19 66 1 0 78 9320 59 0 0 180.
37 33 59 1 0 69 2260 79 0 1 193.
38 139 39 0 0 58 NA 90 0 1 209.
39 38 55 1 0 78 3930 90 1 0 244.
40 27 28 1 0 71 6440 90 0 1 248.
41 58 36 1 0 76 NA 78 1 1 327.
42 61 48 1 0 76 4470 90 0 1 336.
43 42 38 1 0 69 1800 69 0 1 375.
44 28 76 1 0 71 40 90 1 1 419.
Here is the console output:
structure(list(ID = c(44L, 32L, 20L, 17L, 52L, 57L, 79L, 14L,
223L, 56L, 50L, 31L, 35L, 36L, 15L, 12L, 43L, 22L, 54L, 26L,
29L, 25L, 39L, 47L, 49L, 24L, 45L, 30L, 16L, 55L, 37L, 21L, 60L,
18L, 13L, 19L, 33L, 139L, 38L, 27L, 58L, 61L, 42L, 28L, 121L,
192L, 120L, 68L, 41L, 23L, 216L, 136L, 88L, 87L, 182L, 93L, 154L,
94L, 116L, 145L, 228L, 76L, 63L, 59L, 219L, 175L, 164L, 181L,
234L, 146L, 242L, 71L, 67L, 187L, 128L, 151L, 215L, 132L, 173L,
124L, 119L, 224L, 140L, 221L, 172L, 115L, 103L, 73L, 194L, 106L,
193L, 148L, 156L, 203L, 100L, 81L, 190L, 206L, 233L, 189L, 105L,
220L, 85L, 11L, 205L, 131L, 1L, 225L, 183L, 213L, 7L, 147L, 134L,
86L, 69L, 212L, 199L, 75L, 137L, 191L, 245L, 111L, 153L, 112L,
89L, 243L, 109L, 165L, 95L, 231L, 5L, 168L, 159L, 6L, 179L, 77L,
155L, 171L, 174L, 84L, 102L, 207L, 230L, 138L, 188L, 241L, 72L,
235L, 211L, 127L, 237L, 70L, 210L, 110L, 133L, 2L, 218L, 180L,
229L, 65L, 130L, 96L, 226L, 152L, 197L, 178L, 141L, 195L, 92L,
162L, 201L, 217L, 222L, 208L, 104L, 160L, 66L, 74L, 185L, 177L,
123L, 184L, 204L, 227L, 125L, 83L, 8L, 143L, 9L, 3L, 117L, 10L,
198L, 244L, 108L, 34L, 214L, 4L, 97L, 200L, 113L, 80L, 166L,
98L, 238L, 239L, 114L, 167L, 64L, 157L, 90L, 149L, 129L, 170L,
91L, 135L, 122L, 240L, 99L, 236L, 144L, 53L, 176L, 107L, 232L,
163L, 142L, 118L, 126L, 158L, 186L, 82L, 78L, 48L, 62L, 209L,
196L, 46L, 150L, 161L, 169L, 101L, 202L, 51L, 40L), age = c(52L,
66L, 56L, 44L, 49L, 58L, 68L, 74L, 63L, 43L, 54L, 47L, 47L, 64L,
65L, 57L, 59L, 46L, 59L, 66L, 73L, 54L, 54L, 62L, 54L, 47L, 51L,
73L, 57L, 47L, 81L, 46L, 72L, 56L, 53L, 66L, 59L, 39L, 55L, 28L,
36L, 48L, 38L, 76L, NA, 59L, 71L, 58L, 57L, 54L, 69L, 49L, 65L,
48L, 35L, 44L, 65L, 56L, 66L, 41L, 55L, 52L, 67L, 61L, 65L, 61L,
75L, 56L, 37L, 75L, 68L, 59L, 52L, 59L, 59L, 63L, 62L, 57L, 48L,
65L, 41L, 60L, 77L, 66L, 50L, 51L, 81L, 61L, 64L, 48L, 63L, 78L,
79L, 51L, 74L, 52L, 73L, 82L, 58L, 72L, 63L, 67L, 72L, 51L, 68L,
41L, 66L, 69L, 60L, 66L, 71L, 45L, 81L, 52L, 67L, 58L, 63L, 47L,
63L, 67L, 62L, 72L, 75L, 46L, 73L, 57L, 75L, 68L, 68L, 73L, 51L,
59L, 59L, 60L, 54L, 62L, 64L, 48L, 73L, 79L, 58L, 46L, 75L, 63L,
68L, 60L, 54L, 78L, 54L, 46L, 49L, 67L, 79L, 54L, 47L, 51L, 66L,
61L, 64L, 79L, 73L, 51L, 52L, 52L, 76L, 75L, 56L, 76L, 54L, 82L,
62L, 57L, 53L, 42L, 63L, 37L, 66L, 46L, 76L, 39L, 51L, 80L, 69L,
76L, 48L, 65L, 59L, 76L, 57L, 66L, 69L, 68L, 72L, 62L, 56L, 51L,
60L, 71L, 68L, 77L, 28L, 62L, 51L, 61L, 56L, 72L, 79L, 62L, 68L,
68L, 49L, 75L, 64L, 48L, 51L, 68L, 68L, 70L, 73L, 54L, 47L, 79L,
40L, 52L, 58L, 69L, 61L, 44L, 57L, 55L, 43L, 61L, 44L, 77L, 35L,
74L, 72L, 60L, 44L, 53L, 61L, NA, 80L, 73L, 72L), sex = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L,
0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L,
0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L,
1L, 1L, 0L, 1L, 0L, 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0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L), mace_months_date_vs_date_sample = c(30L,
73L, 5L, 77L, 74L, 74L, 45L, 6L, 46L, 70L, 70L, 72L, 77L, 5L,
43L, 71L, 74L, 77L, 71L, 77L, 77L, 73L, 74L, 69L, 28L, 77L, 73L,
68L, 73L, 70L, 74L, 75L, 76L, 69L, 69L, 78L, 69L, 58L, 78L, 71L,
76L, 76L, 69L, 71L, 43L, 44L, 5L, 62L, 73L, 72L, 47L, 61L, 47L,
46L, 44L, 43L, 46L, 45L, 16L, 62L, 8L, 48L, 15L, 79L, 62L, 46L,
62L, 45L, 55L, 21L, 41L, 45L, 46L, 45L, 50L, 62L, 43L, 4L, 1L,
4L, 63L, 17L, 3L, 45L, 2L, 50L, 1L, 44L, 15L, 46L, 46L, 7L, 8L,
62L, 16L, 47L, 19L, 61L, 46L, 1L, 4L, 48L, 61L, 43L, 46L, 61L,
44L, 48L, 1L, 5L, 43L, 43L, 46L, 58L, 3L, 55L, 27L, 1L, 47L,
19L, 11L, 1L, 1L, 1L, 2L, 48L, 62L, 61L, 23L, 1L, 55L, 19L, 48L,
1L, 43L, 47L, 1L, 46L, 11L, 46L, 48L, 46L, 32L, 50L, 61L, 62L,
48L, 46L, 55L, 62L, 55L, 43L, 61L, 47L, 59L, 50L, 10L, 55L, 63L,
55L, 48L, 31L, 32L, 48L, 55L, 62L, 59L, 53L, 48L, 48L, 62L, 59L,
4L, 4L, 25L, 59L, 48L, 60L, 43L, 58L, 49L, 1L, 8L, 1L, 63L, 51L,
55L, 47L, 49L, 55L, 49L, 55L, 13L, 60L, 2L, 13L, 3L, 25L, 7L,
62L, 62L, 60L, 10L, 61L, 45L, 3L, 11L, 51L, 47L, 1L, 46L, 63L,
60L, 43L, 62L, 58L, 61L, 1L, 2L, 46L, 1L, 13L, 54L, 48L, 54L,
45L, 45L, 31L, 48L, 42L, 49L, 43L, 61L, 1L, 31L, 1L, 63L, 11L,
47L, 39L, 7L, 42L, 1L, 1L, 1L), trop = c(2600L, 1710L, NA, 840L,
1740L, 5010L, 776L, 7120L, 4281L, 1360L, 15300L, 6490L, NA, 15940L,
6300L, 6020L, 2100L, 5330L, 1500L, 500L, NA, 1080L, 990L, 1420L,
NA, 2390L, 3710L, 3340L, 180L, NA, NA, 3600L, 470L, 6390L, 1970L,
9320L, 2260L, NA, 3930L, 6440L, NA, 4470L, 1800L, 40L, 21876L,
871L, 7860L, NA, 320L, 8450L, 1730L, 262L, 16720L, 1247L, NA,
NA, 54592L, 1241L, 2413L, NA, 45649L, NA, NA, 160L, 843L, NA,
1470L, 372L, 844L, 1454L, 50000L, 11450L, 769L, 2234L, 349L,
250L, 3654L, 8421L, NA, 5204L, 440L, NA, 40273L, 90L, 9352L,
2177L, 10014L, 11L, 11135L, 5256L, 1753L, NA, NA, 50L, 8903L,
3598L, 2483L, NA, NA, NA, 1557L, 5247L, 24L, 2993L, 3624L, 751L,
NA, NA, 24160L, NA, NA, 5687L, 1911L, NA, NA, 1855L, 9951L, 13374L,
2107L, 4927L, 83L, 2380L, 663L, NA, NA, NA, NA, NA, NA, NA, 1627L,
NA, 1211L, 5654L, NA, NA, 10000L, NA, NA, NA, 2956L, 67927L,
NA, 63L, NA, 4790L, NA, NA, 3569L, 961L, 6581L, 253L, 2888L,
33017L, 1675L, 438L, 15543L, 6212L, 6694L, NA, 1945L, 3004L,
3789L, NA, 2844L, 950L, 123L, 6630L, 3220L, 2040L, NA, 6672L,
1480L, 6979L, NA, 1411L, 5711L, NA, 2340L, NA, 57L, NA, 33L,
5110L, NA, 2797L, 1035L, 2840L, 251L, 7671L, 6155L, 4299L, NA,
846L, 2339L, 400L, 86115L, 27L, 87355L, NA, 8669L, NA, NA, NA,
1258L, 3000L, NA, 137L, 3866L, NA, 1312L, NA, NA, NA, NA, NA,
2103L, 1586L, 601L, 1472L, 1692L, NA, 2102L, 6452L, NA, NA, 1244L,
2051L, 1007L, NA, NA, NA, 1726L, 3400L, 2143L, NA, 236L, 3930L,
31026L, NA, NA, NA, NA, 5280L, 1230L), egfr = c(56L, 90L, 75L,
71L, 71L, 68L, 90L, 78L, 90L, 90L, 90L, 77L, 83L, 52L, 49L, 88L,
84L, 88L, 81L, 51L, 51L, 87L, 77L, 85L, 76L, 90L, 65L, 48L, 99L,
90L, 99L, 87L, 62L, 90L, 87L, 59L, 79L, 90L, 90L, 90L, 78L, 90L,
69L, 90L, 87L, 90L, 58L, 90L, 79L, 55L, 51L, 90L, 58L, 90L, 56L,
62L, 86L, 61L, 84L, 63L, 63L, 90L, 90L, 85L, 64L, 67L, 45L, 90L,
78L, 65L, 69L, 90L, 90L, 59L, 54L, 60L, 68L, 86L, 42L, 73L, 90L,
85L, 63L, 90L, 86L, 68L, 71L, 90L, 68L, 63L, 81L, 76L, 61L, 75L,
84L, 90L, 90L, 48L, 90L, 77L, 68L, 90L, 64L, 90L, 90L, 61L, 84L,
80L, 69L, 58L, 65L, 86L, 86L, 46L, 56L, 90L, 46L, 87L, 84L, 68L,
67L, 72L, 35L, 86L, 74L, 78L, 67L, 90L, 90L, 90L, 76L, 90L, 86L,
63L, 63L, 53L, 90L, 90L, 75L, 64L, 69L, 68L, 52L, 49L, 90L, 65L,
86L, 42L, 63L, 90L, 90L, 73L, 75L, 66L, 64L, 90L, 35L, 90L, 82L,
90L, 84L, 61L, 90L, 86L, 51L, 52L, 69L, 54L, 90L, 75L, 85L, 72L,
90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 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L,
1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
NA, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L), delta_mon1_baseline_to_d3 = c(-821.989379882808,
-562.289733886719, -502.216308593755, -388.549621582031, -372.002563476562,
-308.033813476562, -283.636077880859, -279.422790527344, -218.279922485352,
-173.209777832031, -162.939453124998, -95.700927734375, -70.961883544922,
-69.742797851558, -69.5900268554681, -66.49755859375, -58.77816772461,
-29.29504394531, -25.714111328125, -12.548919677734, -2.99462890625,
2.80639648437602, 32.883270263672, 33.036499023438, 44.05969238281,
47.6982421875, 55.87646484375, 116.716430664065, 130.585632324218,
131.392028808594, 146.8232421875, 153.190795898438, 159.863708496094,
164.985534667969, 179.8525390625, 180.041305541992, 192.978088378906,
208.791275024414, 243.90209960937, 248.09851074219, 327.035522460937,
336.011077880859, 375.086456298828, 419.108337402341, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), stratum = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), .Label = c("1", "2", "3", "4"), class = "factor"), surv = structure(c(30,
73, 5, 77, 74, 74, 45, 6, 46, 70, 70, 72, 77, 5, 43, 71, 74,
77, 71, 77, 77, 73, 74, 69, 28, 77, 73, 68, 73, 70, 74, 75, 76,
69, 69, 78, 69, 58, 78, 71, 76, 76, 69, 71, 43, 44, 5, 62, 73,
72, 47, 61, 47, 46, 44, 43, 46, 45, 16, 62, 8, 48, 15, 79, 62,
46, 62, 45, 55, 21, 41, 45, 46, 45, 50, 62, 43, 4, 1, 4, 63,
17, 3, 45, 2, 50, 1, 44, 15, 46, 46, 7, 8, 62, 16, 47, 19, 61,
46, 1, 4, 48, 61, 43, 46, 61, 44, 48, 1, 5, 43, 43, 46, 58, 3,
55, 27, 1, 47, 19, 11, 1, 1, 1, 2, 48, 62, 61, 23, 1, 55, 19,
48, 1, 43, 47, 1, 46, 11, 46, 48, 46, 32, 50, 61, 62, 48, 46,
55, 62, 55, 43, 61, 47, 59, 50, 10, 55, 63, 55, 48, 31, 32, 48,
55, 62, 59, 53, 48, 48, 62, 59, 4, 4, 25, 59, 48, 60, 43, 58,
49, 1, 8, 1, 63, 51, 55, 47, 49, 55, 49, 55, 13, 60, 2, 13, 3,
25, 7, 62, 62, 60, 10, 61, 45, 3, 11, 51, 47, 1, 46, 63, 60,
43, 62, 58, 61, 1, 2, 46, 1, 13, 54, 48, 54, 45, 45, 31, 48,
42, 49, 43, 61, 1, 31, 1, 63, 11, 47, 39, 7, 42, 1, 1, 1, 1,
0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1,
0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0,
0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0,
0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1), .Dim = c(245L, 2L), .Dimnames = list(
NULL, c("time", "status")), type = "right", class = "Surv")), row.names = c(NA,
-245L), class = c("tbl_df", "tbl", "data.frame"))
Thank you very much for your help,
I fitted some GLMs with a binominal predictor and would like to plot them with visreg. I usually plot the raw data with par(new=T) as well for better clarity. I don't really like the normal outcome here (x-axis 0-1 in 0.2 steps, a lot of data points just at 0 and 1) and was thinking about plotting the visreg over boxplot since they look much better with binominal data. However, I can't get the two plots to align since there are always two different "starts" and "ends" in the plot. How can I make it so that the visreg line starts at the "No" and ends at the "Yes" of the boxplot?
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
boxplot(data$Cov.herb ~ data$Fire, ylim=c(0,100), axes=F, ylab="Herb cover [%]", xlab="Fire")
axis(1, xaxp=c(1,2,1), xaxt="n")
mtext(text=c("No","Yes"),side=1,line=0.5,at=c(1,2))
axis(2, las=1)
box()
par(new=T)
visreg(fit, scale = "response", type="conditional",line=list(col="red", lwd=1), ylim=c(0,100), xlim=c(0,1), rug=F, axes=F, ann=F)
example plot
Cheers,
Alex
data:
structure(list(Cov.herb = c(40L, 80L, 30L, 2L, 40L, 8L, 5L,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 10L, 15L, 25L,
20L, 7L, 25L, 25L, 40L, 35L, 30L, 40L, 25L, 50L, 30L, 25L, 60L,
15L, 25L, 25L, 50L, 30L, 20L, 2L, 3L, 20L, 25L, 35L, 30L, 10L,
15L, 65L, 10L, 20L, 20L, 2L, 7L, 20L, 25L, 30L, 30L, 9L, 20L,
40L, 7L, 20L, 15L, 15L, 30L, 20L, 35L, 8L, 40L, 20L, 3L, 55L,
35L, 10L, 10L, 65L, 20L, 35L, 60L, 45L, 20L, 10L, 35L, 15L, 20L,
15L, 40L, 10L, 10L, 60L, 60L, 40L, 10L, 10L, 25L, 8L, 20L, 40L,
15L, 25L, 5L, 20L, 20L, 20L, 25L, 30L, 35L, 20L, 110L, 50L, 20L,
20L, 10L, 45L, 25L, 20L, 55L, 10L, 5L, 15L, 15L, 1L, 10L, 15L,
15L, 10L, 30L, 20L, 40L, 55L, 55L, 20L, 30L, 10L, 50L, 40L, 5L,
15L, 10L, 30L, 15L, 20L, 5L, 45L, 50L, 25L, 45L, 30L, 7L, 25L,
30L, 5L, 7L, 50L, 60L, 50L, 10L, 30L, 50L, 15L, 15L, 30L, 15L,
25L, 40L, 10L, 2L, 60L, 20L, 65L, 5L, 15L, 3L, 15L, 40L, 50L,
45L, 30L, 5L, 45L, 15L, 25L, 65L, 15L, 50L, 55L, 30L, 10L, 35L,
15L, 20L, 20L, 10L, 20L, 15L, 45L, 40L, 10L, 7L, 25L, 20L, 60L,
4L, 7L, 40L, 60L, 50L, 50L, 10L, 50L, 5L, 10L, 50L, 20L, 40L,
20L, 25L, 25L, 35L, 10L, 2L, 15L, 60L, 25L, 30L, 20L, 25L, 10L,
10L, 20L, 40L, 40L, 45L, 10L, 35L, 60L, 50L, 10L, 40L, 50L, 25L,
20L, 25L, 25L, 45L, 20L, 30L, 65L, 30L, 35L, 40L, 25L, 15L, 10L,
50L, 25L, 45L, 40L, 20L, 5L, 65L, 5L, 10L, 15L, 7L, 20L, 45L,
15L, 5L, 20L, 20L, 20L, 50L,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3L, 4L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 87L, 88L, 89L, 90L,
91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L,
103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L,
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
125L, 126L, 153L, 154L, 155L, 161L, 162L, 163L, 164L, 165L, 166L,
167L, 169L, 170L, 171L, 173L, 174L, 175L, 176L, 177L, 178L, 179L,
180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L,
191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L,
202L, 203L, 204L, 205L, 206L, 207L, 209L, 211L, 213L, 214L, 215L,
216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L,
227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L,
238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
260L, 261L, 262L, 263L, 269L, 270L, 274L, 275L, 276L, 277L, 279L,
280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L,
291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L,
302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L,
324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L,
335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L, 343L, 344L, 345L,
346L, 347L, 349L, 350L, 351L, 352L, 353L, 354L, 355L, 356L, 357L,
358L, 359L, 360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L,
369L, 370L, 371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 380L,
381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L,
392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L,
403L, 404L, 405L, 406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L,
414L, 415L, 416L, 417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L,
425L, 426L, 427L, 428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L,
436L, 437L, 438L, 439L, 440L, 441L, 443L, 444L, 445L, 446L, 447L,
448L, 449L, 450L, 451L, 453L, 454L, 455L, 457L, 458L, 459L, 460L,
461L, 463L, 464L, 465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L,
473L, 474L, 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L,
484L, 485L, 486L, 487L, 488L, 489L, 490L, 491L, 492L, 493L, 494L,
495L, 496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L, 505L,
506L, 507L, 508L, 509L, 510L, 511L, 512L, 513L, 514L, 515L, 516L,
517L, 518L, 519L, 520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L,
528L, 529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L,
539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L, 548L, 549L,
551L, 552L, 553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L,
562L, 563L, 564L, 565L, 566L, 567L, 568L, 569L, 570L, 571L, 572L,
573L, 574L, 575L, 576L, 577L, 578L, 579L, 580L, 581L, 582L, 583L,
584L, 585L, 587L, 588L, 589L, 590L, 591L, 592L, 593L, 594L, 595L,
596L, 597L, 598L, 599L, 600L, 601L, 602L, 603L, 604L, 605L, 606L,
607L, 608L, 609L, 610L, 611L, 612L, 613L, 614L, 615L, 616L, 617L,
618L, 619L, 620L, 621L, 622L, 623L, 624L, 625L, 626L, 628L, 629L,
631L, 632L, 633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L,
642L, 643L, 644L, 645L, 646L, 648L, 649L, 650L, 651L, 652L, 653L,
654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L,
665L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L,
676L, 677L, 678L, 679L, 680L, 682L, 683L, 684L, 685L, 686L, 687L,
689L, 690L, 691L, 692L, 693L, 694L, 697L, 698L, 699L, 700L, 701L,
702L, 704L, 705L, 706L, 707L))
So, my point was that doing it this way would give you more flexibility with your plotting. For example,
# Fit model
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
# Get model data for plotting
vis.out <- visreg(fit, scale = "response", plot = FALSE)
# Load library
library(ggplot2)
# Create plot
p <- ggplot(data = data)
p <- p + geom_boxplot(aes(x = as.factor(Fire), y = Cov.herb, fill = as.factor(Fire)), alpha = 0.3, outlier.alpha = 1)
p <- p + xlab("Fire") + ylab("Herb cover [%]")
p <- p + geom_ribbon(data = vis.out$fit, aes(x = Fire + 1, ymin = visregLwr, ymax = visregUpr), fill = "lightgrey")
p <- p + geom_line(data = vis.out$fit, aes(x = Fire + 1, y = visregFit), colour = "salmon", size = 1.25)
p <- p + scale_x_discrete(labels = c("No", "Yes"))
p <- p + theme(legend.position = "none")
print(p)
gives,
Is that the sort of thing you're looking for? (You could also add all the data points using geom_point to plot on top of the boxes. I think that usually looks pretty cool.)
This question already has answers here:
How to combine scales for colour and size into one legend?
(2 answers)
Closed 7 years ago.
What is the code to make the two legends into one: A circles legend with color?
I think, a single legend with circles colored according to "size" and "# total number of crimes" is the best way to show the legend.
Desired output:
1) There should be one legend: the circles, instead of black should be colored: 0 circle = "yellow" to 800 circle = "red".
My code:
library(maps)
library(ggmap)
Get map from Google Maps
lima <- get_map(location = "lima", zoom = 11, maptype = c("terrain"))
Plot
ggmap(lima) + geom_point(data = limanov2, aes(x = LONGITUD , y = LATITUD, color = TOTALES,
size = TOTALES)) +
scale_size_continuous(name = "Cantidad\ndelitos",range = c(2,12)) +
scale_color_gradient(name = "Cantidad\ndelitos", low = "yellow", high = "red") +
theme(legend.text= element_text(size=14)) +
ggtitle("TOTAL DELITOS - LIMA NOV 2012") +
theme(plot.title = element_text(size = 12, vjust=2, family="Verdana", face="italic"),
legend.position = 'left')
My data:
structure(list(DISTRITO = c("SAN JUAN DE LURIGANCHO", "CALLAO",
"LOS OLIVOS", "ATE", "LIMA", "SAN MARTIN DE PORRES", "SANTIAGO DE SURCO",
"CHORILLOS", "COMAS", "INDEPENDENCIA", "EL AGUSTINO", "LA VICTORIA",
"SAN JUAN DE MIRAFLORES", "VILLA EL SALVADOR", "SAN MIGUEL",
"CARABAYLLO", "MIRAFLORES", "SAN BORJA", "VENTANILLA", "SURQUILLO",
"BREÑA", "ANCON", "PTE. PIEDRA", "RIMAC", "BARRANCO", "LA MOLINA",
"SAN LUIS", "SANTA ANITA", "LURIGANCHO", "P. LIBRE", "MAGDALENA DEL MAR",
"LA PERLA", "CHACLACAYO", "PUENTE PIEDRA", "SAN ISIDRO", "JESUS MARIA",
"BELLAVISTA", "LINCE", "CARMEN DE LA LEGUA REYNOSO", "CIENEGUILLA",
"SANTA ROSA", "LURIN", "PUNTA NEGRA", "PUCUSANA", "LA PUNTA",
"PUNTA HERMOSA", "PACHACAMAC", "SAN BARTOLO", "SANTA MARIA"),
TOTALES = c(861L, 696L, 696L, 642L, 516L, 479L, 442L, 378L,
371L, 368L, 361L, 333L, 325L, 291L, 282L, 251L, 239L, 196L,
193L, 188L, 185L, 174L, 165L, 161L, 138L, 134L, 128L, 119L,
115L, 105L, 67L, 65L, 63L, 58L, 58L, 56L, 45L, 38L, 23L,
23L, 11L, 8L, 6L, 5L, 3L, 3L, 2L, 0L, 0L), HOMICIDIOS = c(1L,
7L, 0L, 1L, 2L, 0L, 0L, 1L, 7L, 4L, 4L, 4L, 0L, 0L, 0L, 2L,
0L, 0L, 7L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 2L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), LESIONES = c(100L, 72L, 61L, 43L, 44L, 8L, 10L,
15L, 44L, 40L, 50L, 15L, 52L, 28L, 7L, 33L, 15L, 3L, 21L,
7L, 36L, 33L, 15L, 19L, 14L, 1L, 8L, 6L, 16L, 4L, 4L, 9L,
1L, 12L, 2L, 9L, 5L, 2L, 5L, 7L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), VIO..DE.LA.LIBERTAD.PERSONAL = c(0L, 7L, 6L,
5L, 6L, 1L, 1L, 0L, 3L, 1L, 2L, 0L, 2L, 0L, 1L, 0L, 1L, 0L,
1L, 1L, 0L, 3L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L,
0L, 1L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), VIO..DE.LA.LIBERTAD.SEXUAL = c(56L, 14L, 12L, 15L, 7L,
10L, 2L, 9L, 11L, 13L, 8L, 9L, 7L, 14L, 4L, 15L, 4L, 2L,
17L, 7L, 3L, 4L, 6L, 12L, 2L, 1L, 5L, 3L, 11L, 4L, 1L, 2L,
0L, 6L, 2L, 0L, 3L, 0L, 2L, 2L, 0L, 4L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), HURTO.SIMPLE.Y.AGRAVADO = c(217L, 203L, 296L, 230L,
260L, 167L, 226L, 217L, 130L, 117L, 154L, 133L, 121L, 46L,
163L, 72L, 161L, 119L, 69L, 120L, 64L, 19L, 64L, 21L, 57L,
44L, 39L, 2L, 48L, 60L, 30L, 19L, 48L, 20L, 41L, 25L, 19L,
27L, 7L, 11L, 9L, 0L, 6L, 0L, 2L, 3L, 1L, 0L, 0L), ROBO.SIMPLE.Y.AGRAVADO = c(460L,
289L, 308L, 344L, 186L, 277L, 198L, 130L, 165L, 184L, 137L,
149L, 134L, 188L, 104L, 126L, 58L, 72L, 64L, 51L, 77L, 115L,
79L, 76L, 64L, 88L, 73L, 108L, 40L, 36L, 30L, 32L, 14L, 17L,
12L, 22L, 12L, 8L, 6L, 3L, 1L, 3L, 0L, 2L, 1L, 0L, 1L, 0L,
0L), MICRO.COM.DE.DROGAS = c(26L, 100L, 13L, 3L, 10L, 15L,
5L, 5L, 11L, 8L, 3L, 23L, 9L, 15L, 3L, 3L, 0L, 0L, 8L, 2L,
5L, 0L, 0L, 28L, 0L, 0L, 1L, 0L, 0L, 0L, 2L, 2L, 0L, 2L,
0L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L
), TENENCIA.ILEGAL.DE.ARMAS = c(1L, 4L, 0L, 1L, 1L, 1L, 0L,
1L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), LONGITUD = c(-77,
-77.12, -77.08, -76.89, -77.04, -77.09, -76.99, -77.01, -77.05,
-77.05, -77, -77.02, -76.97, -76.94, -77.09, -76.99, -77.03,
-77, -77.13, -77.01, -77.05, -77.11, -77.08, -76.7, -77.02,
-76.92, -77, -76.96, -76.86, -77.06, -77.07, -77.12, -76.76,
-77.08, -77.03, -77.05, -77.11, -77.04, -77.09, -76.78, -77.16,
-76.81, -76.73, -76.77, -77.16, -76.76, -76.83, -76.73, -76.77
), LATITUD = c(-11.99, -12.04, -11.95, -12.04, -12.06, -12,
-12.16, -12.2, -11.93, -11.99, -12.04, -12.08, -12.16, -12.23,
-12.08, -11.79, -12.12, -12.1, -11.89, -12.11, -12.06, -11.69,
-11.88, -11.94, -12.15, -12.09, -12.08, -12.04, -11.98, -12.08,
-12.09, -12.07, -11.99, -11.88, -12.1, -12.08, -12.06, -12.09,
-12.04, -12.07, -11.81, -12.24, -12.32, -12.47, -12.07, -12.28,
-12.18, -12.38, -12.42)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -49L), .Names = c("DISTRITO", "TOTALES",
"HOMICIDIOS", "LESIONES", "VIO..DE.LA.LIBERTAD.PERSONAL", "VIO..DE.LA.LIBERTAD.SEXUAL",
"HURTO.SIMPLE.Y.AGRAVADO", "ROBO.SIMPLE.Y.AGRAVADO", "MICRO.COM.DE.DROGAS",
"TENENCIA.ILEGAL.DE.ARMAS", "LONGITUD", "LATITUD"))
I've found a solution. Reading the documention for GGPLOT2 V. 0.9
It is the new function: guide_legend() that should be used inside guides().
This is a function that lets you have more control over legend labels.
This is the end code with the resulting output (See the last line):
ggmap(lima) + geom_point(data = limanov2, aes(x = LONGITUD , y = LATITUD, color = TOTALES,
size = TOTALES)) +
scale_size_continuous(name = "Cantidad\ndelitos",range = c(2,12)) +
scale_color_gradient(name = "Cantidad\ndelitos", low = "yellow", high = "red") +
theme(legend.text= element_text(size=14)) +
ggtitle("TOTAL DELITOS - LIMA NOV 2012") +
theme(plot.title = element_text(size = 12, vjust=2, family="Verdana", face="italic"),
legend.position = 'left') +
guides(colour = guide_legend())
I'm plotting some points over a map with ggmap package.
The problem is that i get the message: "Removed 12 rows containing missing values (geom_point)".
But i don't have any NAs. I've looked the data, and used:
sum(is.na(limanov2)) #Gives 0
to prove it.
This is my code:
library(maps)
library(ggmap)
lima <- get_map(location = "lima", zoom = 11)
ggmap(lima) + geom_point(data = limanov2, aes(x = LONGITUD , y = LATITUD, color = TOTALES,
size = TOTALES)) +
scale_color_gradient(low = "yellow", high = "red")
My data:
structure(list(DISTRITO = c("SAN JUAN DE LURIGANCHO", "CALLAO",
"LOS OLIVOS", "ATE VITARTE", "LIMA CERCADO", "SAN MARTÍN", "SANTIAGO DE SURCO",
"CHORILLOS", "COMAS", "INDEPENDENCIA", "EL AGUSTINO", "LA VICTORIA",
"SAN JUAN DE MIRAFLORES", "VILLA EL SALVADOR", "S. MIGUEL", "CARABAYLLO",
"MIRAFLORES", "PTE. PIEDRA", "SAN BORJA", "VENTANILLA", "SURQUILLO",
"BREÑA", "ANCÓN", "EL RIMAC", "BARRANCO", "LA MOLINA", "SAN LUIS",
"STA. ANITA", "LURIGANCHO", "P. LIBRE", "MAGDALENA", "LA PERLA",
"CHACLACAYO", "SAN ISIDRO", "J. MARÍA", "BELLAVISTA", "LINCE",
"C. DE LA LEGUA", "CIENEGUILLA", "STA.ROSA", "LURÍN", "PTA.NEGRA",
"PUCUSANA", "LA PUNTA", "PTA. HERMOSA", "PACHACAMAC", "SAN BARTOLO",
"SANTA MARÍA"), TOTALES = c(861L, 696L, 696L, 642L, 516L, 479L,
442L, 378L, 371L, 368L, 361L, 333L, 325L, 291L, 282L, 251L, 239L,
223L, 196L, 193L, 188L, 185L, 174L, 161L, 138L, 134L, 128L, 119L,
115L, 105L, 67L, 65L, 63L, 58L, 56L, 45L, 38L, 23L, 23L, 11L,
8L, 6L, 5L, 3L, 3L, 2L, 0L, 0L), HOMICIDIOS = c(1L, 7L, 0L, 1L,
2L, 0L, 0L, 1L, 7L, 4L, 4L, 4L, 0L, 0L, 0L, 2L, 0L, 1L, 0L, 7L,
0L, 0L, 0L, 4L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), LESIONES = c(100L,
72L, 61L, 43L, 44L, 8L, 10L, 15L, 44L, 40L, 50L, 15L, 52L, 28L,
7L, 33L, 15L, 27L, 3L, 21L, 7L, 36L, 33L, 19L, 14L, 1L, 8L, 6L,
16L, 4L, 4L, 9L, 1L, 2L, 9L, 5L, 2L, 5L, 7L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), VIO..DE.LA.LIBERTAD.PERSONAL = c(0L, 7L,
6L, 5L, 6L, 1L, 1L, 0L, 3L, 1L, 2L, 0L, 2L, 0L, 1L, 0L, 1L, 1L,
0L, 1L, 1L, 0L, 3L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L,
0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), VIO..DE.LA.LIBERTAD.SEXUAL = c(56L,
14L, 12L, 15L, 7L, 10L, 2L, 9L, 11L, 13L, 8L, 9L, 7L, 14L, 4L,
15L, 4L, 12L, 2L, 17L, 7L, 3L, 4L, 12L, 2L, 1L, 5L, 3L, 11L,
4L, 1L, 2L, 0L, 2L, 0L, 3L, 0L, 2L, 2L, 0L, 4L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), HURTO.SIMPLE.Y.AGRAVADO = c(217L, 203L, 296L, 230L,
260L, 167L, 226L, 217L, 130L, 117L, 154L, 133L, 121L, 46L, 163L,
72L, 161L, 84L, 119L, 69L, 120L, 64L, 19L, 21L, 57L, 44L, 39L,
2L, 48L, 60L, 30L, 19L, 48L, 41L, 25L, 19L, 27L, 7L, 11L, 9L,
0L, 6L, 0L, 2L, 3L, 1L, 0L, 0L), ROBO.SIMPLE.Y.AGRAVADO = c(460L,
289L, 308L, 344L, 186L, 277L, 198L, 130L, 165L, 184L, 137L, 149L,
134L, 188L, 104L, 126L, 58L, 96L, 72L, 64L, 51L, 77L, 115L, 76L,
64L, 88L, 73L, 108L, 40L, 36L, 30L, 32L, 14L, 12L, 22L, 12L,
8L, 6L, 3L, 1L, 3L, 0L, 2L, 1L, 0L, 1L, 0L, 0L), MICRO.COM.DE.DROGAS = c(26L,
100L, 13L, 3L, 10L, 15L, 5L, 5L, 11L, 8L, 3L, 23L, 9L, 15L, 3L,
3L, 0L, 2L, 0L, 8L, 2L, 5L, 0L, 28L, 0L, 0L, 1L, 0L, 0L, 0L,
2L, 2L, 0L, 0L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L,
0L, 0L), TENENCIA.ILEGAL.DE.ARMAS = c(1L, 4L, 0L, 1L, 1L, 1L,
0L, 1L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), LONGITUD = c(-77, -77.12,
-77.08, -76.89, -77.04, -77.09, -76.99, -77.01, -77.05, -77.05,
-77, -77.02, -76.97, -76.94, -77.09, -76.99, -77.03, -77.08,
-77, -77.13, -77.01, -77.05, -77.11, -76.7, -77.02, -76.92, -77,
-76.96, -76.86, -77.06, -77.07, -77.12, -76.76, -77.03, -77.05,
-77.11, -77.04, -77.09, -76.78, -77.16, -76.81, -76.73, -76.77,
-77.16, -76.76, -76.83, -76.73, -76.77), LATITUD = c(-11.99,
-12.04, -11.97, -12.04, -12.06, -12, -12.16, -12.2, -11.93, -11.99,
-12.04, -12.08, -12.16, -12.23, -12.08, -11.79, -12.12, -11.88,
-12.1, -11.89, -12.11, -12.06, -11.69, -11.94, -12.15, -12.09,
-12.08, -12.04, -11.98, -12.08, -12.09, -12.07, -11.99, -12.1,
-12.08, -12.06, -12.09, -12.04, -12.07, -11.81, -12.24, -12.32,
-12.47, -12.07, -12.28, -12.18, -12.38, -12.42)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -48L), .Names = c("DISTRITO",
"TOTALES", "HOMICIDIOS", "LESIONES", "VIO..DE.LA.LIBERTAD.PERSONAL",
"VIO..DE.LA.LIBERTAD.SEXUAL", "HURTO.SIMPLE.Y.AGRAVADO", "ROBO.SIMPLE.Y.AGRAVADO",
"MICRO.COM.DE.DROGAS", "TENENCIA.ILEGAL.DE.ARMAS", "LONGITUD",
"LATITUD"))
You have values outside of the base map zoom range... try changing your zoom parameter.
library(maps)
library(ggmap)
lima <- get_map(location = "lima", zoom = 10)
ggmap(lima) +
geom_point(data = limanov2,
aes(x = LONGITUD , y = LATITUD,
color = TOTALES, size = TOTALES)) +
scale_color_gradient(low = "yellow", high = "red")