How to display the intersection points of y axis? - r

library(data.table)
library(survival)
library(survminer)
library(dcurves)
I have df as follows
structure(list(PatientID = c(1001L, 1002L, 1003L, 1004L, 1006L,
1014L, 1015L, 1016L, 1018L, 1022L, 1024L, 1032L, 1040L, 1042L,
1049L, 1056L, 1059L, 1060L, 1066L, 1084L, 1087L, 1090L, 1093L,
1096L, 1097L, 1098L, 1099L, 1200L, 1205L, 1216L, 1221L, 1222L,
1225L, 1226L, 1233L, 1239L), TimeMonths = c(9L, 8L, 69L, 104L,
104L, 100L, 24L, 85L, 100L, 99L, 67L, 58L, 7L, 94L, 93L, 90L,
91L, 90L, 89L, 72L, 84L, 84L, 11L, 82L, 39L, 46L, 82L, 82L, 9L,
34L, 75L, 76L, 52L, 20L, 29L, 70L), Event = c(1L, 0L, 0L, 0L,
0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L
), P1 = c(0.1, 0.03, 0.02, 0.05, 0.01, 0.04, 0.03,
0.06, 0.02, 0.03, 0, 0, 0.11, 0.01, 0.03, 0, 0.01, 0.01, 0.01,
0, 0, 0, 0.05, 0.01, 0, 0, 0, 0, 0.04, 0, 0.07, 0.01, 0.01, 0,
0, 0), Age = c(88L, 49L, 60L, 46L, 50L, 60L, 38L, 74L, 39L, 65L,
80L, 35L, 54L, 40L, 54L, 55L, 60L, 38L, 64L, 74L, 71L, 57L, 55L,
49L, 42L, 30L, 63L, 46L, 47L, 58L, 34L, 72L, 50L, 60L, 73L, 51L
), Grade = c(2L, 2L, 2L, 3L, 3L, 1L, 2L, 2L, 2L, 1L, 2L, 1L,
3L, 1L, 3L, NA, 2L, 3L, 2L, 2L, 2L, NA, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L), Tsize = c(2.5, 6, 4, 4, 3.5,
1.8, 1.5, 1.5, 2, 3.5, 4, 2, 4.5, 3, 3, 2, 3, 1.5, 2.5, 5, 5,
3, 6, 3, 2.5, 5, 1.5, 2, 5.5, 5, 3, 6, 4, 3.5, 4, 5), LNstatus = c(0L,
1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L,
1L, 1L, 0L), Time = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5), Model1 = c(0.0754111003682264, 0.789025824308725, 0.0888669573431788,
0.162944690463524, 0.148205788806964, 0.0232412222825853, 0.335639290548721,
0.427877640015971, 0.0437151408243315, 0.340118759660636, 0.104749557872707,
0.191041558905319, 0.901494025297558, 0.0271621117477482, 0.134690848022469,
NA, 0.0681964605449713, 0.0799110215826685, 0.0617151301818596,
0.129265190806531, 0.760358458474655, NA, 0.805815477115913,
0.0622010539620427, 0.4275233016386, 0.632818820863808, 0.39812097019303,
0.0217733118415042, 0.118190758626649, 0.721016961718498, 0.449778991144841,
0.164102951793386, 0.857780996059435, 0.576334735175668, 0.668186510212559,
0.107238793230798), Model2 = c(0.444752330666943, 0.930853771862407,
0.0980811416950194, 0.311714208416219, 0.108779198079316, 0.0297296718406789,
0.255165235219636, 0.652922467522166, 0.0301952043412281, 0.405213119172736,
0.0800242041001141, 0.0767147984837693, 0.999999999862285, 0.0181219543140756,
0.14865830843794, NA, 0.0496630840467432, 0.0382325860289233,
0.0421016493675688, 0.113455005788149, 0.665969059849803, NA,
0.991966233874329, 0.0424861062828985, 0.206267128670341, 0.453591375821231,
0.180419209497713, 0.00979786791522574, 0.243955485600603, 0.596589087934302,
0.778048018064795, 0.211053490646643, 0.747102269303274, 0.37666971629859,
0.511588083962541, 0.0826035699229486)), class = "data.frame", row.names = c(NA,
-36L))
I tried following code to generate the dca
dca(Surv(Time, Event) ~ Model1 + Model2, data = dfs,
label = list(Model1 = "Model1", Model2 = "Model2"), time = 5, thresholds = 1:35 / 100) %>% plot(smooth = TRUE)
Now I want to display the values of y axis at a specific x value for Model1 and Model2. It's approximately 0.255 and 0.300 respectively
Expected output

Related

How to use Predict in rms package for a multiple values?

I used cox model for Predict function rms package for individual values they are returning the correct result where as when I give multiple values it gives me weired results?
library(data.table)
library(survival)
library(survminer)
library(rms)
dput(df)
structure(list(ID = c(1001L, 1002L, 1003L, 1004L, 1006L, 1014L,
1015L, 1016L, 1018L, 1022L, 1024L, 1032L, 1040L, 1042L, 1049L,
1056L, 1059L, 1060L, 1066L, 1084L, 1087L, 1090L, 1093L, 1096L,
1097L, 1098L, 1099L, 1200L, 1205L, 1216L, 1221L, 1222L, 1225L,
1226L, 1233L, 1239L), Time = c(9L, 8L, 69L, 104L, 104L, 100L,
24L, 85L, 100L, 99L, 67L, 58L, 7L, 94L, 93L, 90L, 91L, 90L, 89L,
72L, 84L, 84L, 11L, 82L, 39L, 46L, 82L, 82L, 9L, 34L, 75L, 76L,
52L, 20L, 29L, 70L), Event = c(1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L), Risk1 = c(0.1,
0.03, 0.02, 0.05, 0.01, 0.04, 0.03, 0.06, 0.02, 0.03, 0, 0, 0.11,
0.01, 0.03, 0, 0.01, 0.01, 0.01, 0, 0, 0, 0.05, 0.01, 0, 0, 0,
0, 0.04, 0, 0.07, 0.01, 0.01, 0, 0, 0), Risk2 = c(88L, 49L, 60L,
46L, 50L, 60L, 38L, 74L, 39L, 65L, 80L, 35L, 54L, 40L, 54L, 55L,
60L, 38L, 64L, 74L, 71L, 57L, 55L, 49L, 42L, 30L, 63L, 46L, 47L,
58L, 34L, 72L, 50L, 60L, 73L, 51L), Risk3 = c(2L, 2L, 2L, 3L,
3L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 3L, 1L, 3L, NA, 2L, 3L, 2L, 2L,
2L, NA, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L
)), class = "data.frame", row.names = c(NA, -36L)
followed by
ddist <- datadist(df)
options(datadist='ddist')
cox_model <-cph(Surv(Time,Event==1) ~ Risk1 + Risk2 + Risk3, x = T, y = T, data = df, surv = T)
Predict(cox_model, Risk1=3.2, Risk2=1, Risk3=0.5)
but when I give multiple values as follows:
Predict(cox_model,
Risk1=c(5,3,2,1.5,1.5,2,3,2.5,4,2,5.5,6,3,3.5,4,5,4.5,3,2,6,3,5,4,1.8,3,3.5,1.5,2.5,3.5,5,6,4,1.5,5,4,2.5),
Risk2=c(1,1,1,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,0,1,1,0,0,0),
Risk3=c(0,0.07,0,0.03,0.01,0.02,0.01,0,0.05,0,0.04,0.03,0.01,0.01,0.01,0,0.11,0.03,0,0.05,0,0,0.02,0.04,0.01,0,0,0.01,0.03,0,0.01,0,0.06,0,0,0.1))
It gives me a ouput with 46566 rows where as I have only 36 rows to predict

Create a condition for legend in ggsurvplot

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, 1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L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L,
0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 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,
90L, 80L, 54L, 58L, 90L, 89L, 72L, 90L, 84L, 33L, 74L, 36L, 56L,
61L, 63L, 77L, 84L, 85L, 90L, 90L, 51L, 90L, 90L, 68L, 90L, 52L,
90L, 48L, 90L, 82L, 86L, 67L, 90L, 76L, 14L, 63L, 59L, 82L, 90L,
39L, 77L, 90L, 78L, 74L, 54L, 36L, 58L, 69L, NA, 53L, 90L, 90L,
90L, 88L, 90L, 90L, 90L, 90L, 90L, 63L, 87L, 48L, 90L, 55L, 70L,
65L, 90L, NA, 90L, 90L, 72L, 66L, 55L), dm = c(1L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L,
0L, 0L, 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0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 0L, 1L, 1L, 0L, 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,

"Error: Aesthetics must be either length 1 or the same as the data" when plotting line with ggplot2

I have a a matrix with data, I fit a glm to slices of the matrix, plot histogram, and plot an estimated density according to glm parameter. Then, I want to save all the plots into one pdf file.
n_clusters <- length(levels(SNF_W_louvain))
n_features <- dim(filtered_ADT_counts)[1]
all_plots <- vector("list", n_clusters * n_features)
i <- 1
for(current_cluster in 1:n_clusters) {
for(current_marker in 1:n_features) {
current_data <- data.frame(counts = filtered_ADT_counts[current_marker, SNF_W_louvain == current_cluster])
fit_poisson <- glm(counts ~ 1, current_data, family = "poisson")
fit_info <- paste0("AIC: ", round(fit_poisson$aic, 2), " (Pois)")
plot_title <- paste0("Protein: ", rownames(filtered_ADT_counts)[current_marker], " Cluster: ", current_cluster)
pred_density_pois <- dpois(current_data$counts, lambda = exp(fit_poisson$coefficients[1]))
current_plot <- current_data %>%
ggplot() +
geom_histogram(aes(x = counts, y=..density..), fill = "white", color='red') +
geom_line(aes(x = counts, y = pred_density_pois), color= 'blue') +
ggtitle(plot_title) +
annotate("text", x = Inf, y = Inf, hjust = 1, vjust = 2, label = fit_info, size = 3)
all_plots[[i]] <- current_plot
i <- i + 1
}
}
ggsave(
filename = "all_plots.pdf",
plot = marrangeGrob(all_plots, nrow=4, ncol=2),
units = "mm",
width = 210,
height = 297
)
I get the following error:
Aesthetics must be either length 1 or the same as the data (30): y
Backtrace:
1. ggplot2::ggsave(...)
3. gridExtra::marrangeGrob(all_plots, nrow = 4, ncol = 2)
6. base::lapply(grobs[toconv], ggplot2::ggplotGrob)
7. ggplot2:::FUN(X[[i]], ...)
10. ggplot2:::ggplot_build.ggplot(x)
11. ggplot2:::by_layer(function(l, d) l$compute_aesthetics(d, plot))
12. ggplot2:::f(l = layers[[i]], d = data[[i]])
13. l$compute_aesthetics(d, plot)
14. ggplot2:::f(..., self = self)
15. ggplot2:::check_aesthetics(evaled, n)
When I remove this line:
geom_line(aes(x = counts, y = pred_density_pois), color= 'blue') +
it actually works.
Any tips appreciated!
Data:
filtered_ADT_counts
new("dgCMatrix", i = c(0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L,
0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L,
0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L,
0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L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 53L, 54L, 55L, 56L, 57L, 58L, 58L, 59L,
61L, 62L, 63L, 64L, 66L, 66L, 68L, 69L, 70L, 70L, 72L, 74L, 75L,
76L, 78L, 80L, 82L, 84L, 85L, 86L, 86L, 87L, 89L, 90L, 90L, 91L,
92L, 93L, 94L, 96L, 98L, 98L, 100L, 101L, 102L, 104L, 106L, 107L,
109L, 111L, 111L, 112L, 112L, 113L, 114L, 115L, 117L, 118L, 119L,
120L, 122L, 124L, 125L, 127L, 128L, 129L, 131L, 132L, 132L, 133L,
134L, 136L, 137L, 137L, 138L, 138L, 139L, 141L, 143L, 145L, 147L,
148L, 150L, 152L, 153L, 154L, 154L, 156L, 158L, 159L, 161L, 161L,
163L, 165L, 166L, 167L, 168L, 169L, 171L, 173L, 175L, 176L, 178L,
179L, 181L, 183L, 184L, 185L, 186L, 187L, 189L, 190L, 192L, 194L,
195L, 196L, 197L, 199L, 200L, 201L, 203L, 204L, 205L, 205L, 206L,
206L, 207L, 208L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 216L,
218L, 219L, 220L, 220L, 221L, 223L, 223L, 225L, 226L, 227L, 228L,
230L, 231L, 233L, 234L, 236L, 237L, 238L, 239L, 239L, 241L, 242L,
242L, 244L, 245L, 246L, 248L, 249L, 251L, 252L, 254L, 255L, 256L,
257L, 258L, 259L, 261L, 263L, 265L, 265L, 266L, 267L, 269L, 271L,
272L, 274L, 276L, 278L, 278L, 279L, 281L, 282L, 284L, 286L, 287L,
289L, 290L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 298L, 299L,
301L, 301L, 302L, 304L, 305L, 307L, 307L, 308L, 310L, 311L, 311L,
312L, 313L, 314L, 315L, 317L, 318L, 320L, 321L, 321L, 322L, 323L,
325L, 327L, 328L, 329L, 331L, 333L, 334L, 336L, 336L, 338L, 339L,
340L, 342L, 344L, 346L, 347L, 347L, 349L, 351L, 353L, 354L, 355L,
355L, 356L, 356L, 357L, 359L, 360L, 362L, 364L, 366L, 367L, 367L,
369L, 371L, 372L, 373L, 375L, 377L, 379L, 380L, 382L, 383L, 385L,
386L, 388L, 389L, 390L, 391L, 392L, 394L, 394L, 395L, 397L, 398L,
400L, 402L, 403L, 404L, 404L, 406L, 407L, 408L, 409L, 411L, 413L,
414L, 415L, 416L, 417L, 419L, 420L, 421L, 423L, 425L, 426L, 427L,
427L, 428L, 429L, 429L, 431L, 433L, 434L, 436L, 437L, 439L, 440L,
442L, 444L, 445L, 446L, 447L, 448L, 450L, 452L, 454L, 456L, 458L,
459L, 460L, 461L, 463L, 464L, 466L, 467L, 469L, 470L, 472L, 473L,
474L, 475L, 476L, 477L, 478L, 479L, 479L, 481L, 482L, 484L, 485L,
486L, 487L, 489L, 491L, 492L, 494L, 495L, 496L, 498L, 499L, 501L,
502L, 503L, 505L, 506L, 507L, 508L, 509L, 510L, 511L, 513L, 515L,
517L, 519L, 521L, 522L, 523L, 523L, 525L, 525L, 527L, 529L, 530L,
532L, 533L, 534L, 535L, 537L, 539L, 541L, 543L, 544L, 545L, 546L,
548L, 548L, 549L, 551L), Dim = c(2L, 437L), Dimnames = list(c("B220 (CD45R)",
"B7-H1 (PD-L1)"), c("GATCGCGGTTATCGGT", "GGCTGGTAGAGGTTAT", "ACAGCTACAGATCGGA",
"CAACTAGCAGCTCGAC", "TCTCATACATCGATGT", "AGCATACTCTCCCTGA", "CAACCTCCAGTACACT",
"TCGGGACAGGATGTAT", "TCTCTAATCAGAGCTT", "CAGAATCTCCGGCACA", "GTTAAGCTCGAATGGG",
"TACTTACAGTTGTCGT", "CTAAGACTCTTCTGGC", "GTAGGCCCACTGTCGG", "CGATGGCCAAACAACA",
"GACGGCTGTGATGTCT", "TGGTTCCTCAACACTG", "CCTAGCTGTTACGGAG", "CAGCCGAAGACTACAA",
"TGACAACTCTCTGCTG", "GTTCATTTCCCACTTG", "GCATGATAGGTGTTAA", "TTCTCAATCTTTCCTC",
"GCACATATCTCTAAGG", "TTGTAGGTCCGTCATC", "TCATTACGTCTCAACA", "AGCTCCTTCACGCGGT",
"ACTGATGAGATACACA", "CAACTAGAGTACGACG", "CAAGTTGGTTTAGGAA", "TGAGCATTCACGAAGG",
"CCATTCGCAGAGTGTG", "CTACACCGTAAGTGGC", "CGAGCACCATTAGCCA", "CGTTCTGCATCCAACA",
"GGCTCGAGTCCTCTTG", "GCCTCTACATGGTCTA", "GCATACAGTAGCGTGA", "GAACGGAGTCAACATC",
"AGTCTTTAGATCCCGC", "AGACGTTAGTCTTGCA", "GGGTCTGTCGTAGGAG", "AAGGTTCTCTTGAGAC",
"GTGAAGGTCACATGCA", "TAAACCGAGAGTCGGT", "TAGTTGGAGGCCCTCA", "TAGTGGTAGTCTCCTC",
"TTAGGCAGTTGCTCCT", "CGGTTAAGTTCCTCCA", "TTATGCTTCTGTGCAA", "ATCCACCCACATTCGA",
"TGCACCTCAGAGTGTG", "GGGTTGCCACTGCCAG", "AGTCTTTCATCGGTTA", "AGTGAGGTCGATGAGG",
"GCGCAGTGTCGAATCT", "CAGCTGGGTAATCACC", "GTGAAGGGTTCCGTCT", "TACCTATGTCACTGGC",
"GCAGCCAGTAGTACCT", "CATGCCTCATGCCCGA", "GATCAGTTCCGTCATC", "ACGTCAAAGTCGCCGT",
"GCTTGAATCATCGGAT", "AAGTCTGCACATGGGA", "GTTCGGGGTTCACGGC", "GTGTTAGCATTCGACA",
"ATAGACCAGGACAGAA", "TAGAGCTGTGAGGGAG", "TCAGATGCAGCGTAAG", "ATTATCCTCATACGGT",
"TGAGCCGTCCCGGATG", "AGATTGCGTCTACCTC", "GCGCAGTGTCAAAGAT", "TGAGGGAAGAACAACT",
"GACTAACTCACAGGCC", "CCTTCGAAGGGAAACA", "CGTGAGCAGTTTGCGT", "CGTCTACTCTTGGGTA",
"GGTGCGTCATACTCTT", "TCAATCTGTCTTGCGG", "TGAGAGGAGGGTCGAT", "TAGAGCTTCCCGACTT",
"TGTGGTAAGAATGTGT", "ACACCCTCAACACCTA", "AGTCTTTCACATTAGC", "TGAAAGAAGCGTAATA",
"TGCACCTCACAACGTT", "AATCGGTAGCTCTCGG", "CGAGCCAGTAGTAGTA", "TCCACACAGAAGGACA",
"AGGGAGTAGATGTAAC", "GAGTCCGAGCTCCTCT", "GCTTCCACAGACAAAT", "GCCTCTAGTTAAGACA",
"CGCTGGAGTCACTTCC", "CGTGTAACATGGGAAC", "CTAACTTAGCGATATA", "TCAGGTAAGGGTTCCC",
"TTAGTTCTCGAGAACG", "CAGCTAACAAACTGCT", "TAAGAGAGTCTTGTCC", "GTGTGCGTCCGTTGTC",
"TCGAGGCGTCTTGTCC", "GACAGAGTCAAAGACA", "TGATTTCGTCACACGC", "CGCGGTACACTTCTGC",
"CTAGCCTTCCGTCAAA", "CTACACCCAAGAAAGG", "GTGTGCGGTCAATACC", "CCATTCGAGCACAGGT",
"CGAACATAGCAGATCG", "CGATGGCAGTACGATA", "AAATGCCAGCAACGGT", "AGGTCCGCACGAAGCA",
"AGTGGGACAAGTTGTC", "TTATGCTAGTACGACG", "CTGCGGATCCATGAAC", "ACTTGTTCAAATTGCC",
"GTGCTTCCAGGAATCG", "GCTTCCAGTGGTAACG", "ACGCCGATCTTTCCTC", "GCTGGGTCAACAACCT",
"CATGGCGGTCCAGTGC", "CGGACACAGCTGTTCA", "ACGCAGCAGCTACCGC", "CAAGGCCTCATAACCG",
"TGAGCATCAGCCTTTC", "ATCATGGTCGCTTAGA", "TGCGGGTGTTGTACAC", "GAATGAAGTCAGTGGA",
"TGTGGTACATAAAGGT", "TTTATGCTCACCATAG", "CGACTTCAGGATCGCA", "GTGCGGTGTAGAGCTG",
"TGCTACCAGAGGACGG", "CGTTCTGTCCTAGGGC", "GAAACTCGTTCCCGAG", "CATCAAGCAATTGCTG",
"GGGTTGCTCCGTAGTA", "CTGCGGATCCGCATCT", "GAAGCAGGTAGCGCAA", "TGTATTCAGATAGGAG",
"TCAACGACAAGACGTG", "GCCAAATTCGAGGTAG", "TTAGTTCCATCCGCGA", "TTGGCAAGTTCCATGA",
"GTTCGGGGTACCGTTA", "CCCAATCAGTTGTCGT", "CGATGTATCGATGAGG", "CTCGGGACATATACCG",
"TCGAGGCTCTTAGCCC", "TAAGCGTTCACGGTTA", "CTTGGCTAGTGCTGCC", "AGTGGGACAGCTGCAC",
"TTGCGTCAGTAGATGT", "CTGCGGACAGCTCCGA", "TGCGTGGCACATTTCT", "CATGGCGAGGCTATCT",
"GGGATGACATCTCCCA", "GACCTGGGTCTCTTAT", "CAGCTGGCAAGAAGAG", "TAGCCGGAGCAGGTCA",
"CAGCTAATCACAGTAC", "TATTACCTCCTTGCCA", "CTCGTCACATTCTCAT", "TCAACGATCTTTAGTC",
"CTGAAGTCACTCAGGC", "TCAGCTCAGTTGTCGT", "CATTATCGTAAGTTCC", "GTGGGTCGTAGCGCAA",
"CATGACAGTCTAACGT", "CAGTCCTAGGACACCA", "CTCAGAAGTCGAATCT", "GGGTCTGTCCACGAAT",
"GCTGCGAAGCCACGTC", "GAATGAAGTGAGTATA", "TGCTGCTCATGCTGGC", "GCTTGAAGTTGGTAAA",
"GATGCTAGTGCTTCTC", "GTACTCCCACTGCCAG", "AGCAGCCCAAGTCTGT", "GAAGCAGGTTAAGGGC",
"ACCTTTACAGGGTACA", "ACTGTCCAGTATTGGA", "ACTTGTTAGAGTCTGG", "CGGAGTCAGCTAGTTC",
"CCGTGGATCGACCAGC", "CAGCTGGCATACGCTA", "CTGCTGTTCATTGCCC", "GGGTTGCTCATCATTC",
"GCATGCGGTTTAGGAA", "ATCACGAGTGGGTCAA", "ACATACGCACGGTAGA", "CCTAAAGTCCGTAGTA",
"CAACCTCGTAGCAAAT", "AAGGTTCGTAAGGGAA", "CGGACTGTCGGTGTTA", "GATCGATCAGCTGGCT",
"GCGCAACAGCTATGCT", "GCAAACTTCCGCAGTG", "TTGAACGAGAGGTAGA", "TAAGTGCTCGCCAGCA",
"GTGCATAAGAAACGAG", "GCAATCAGTACGAAAT", "TACACGAAGTCGAGTG", "AGAGCTTCACTTGGAT",
"GACGGCTCACATCTTT", "TATCTCACACTGCCAG", "GCACATATCTCCAACC", "TGCCCTATCGGATGTT",
"GATGCTAGTAGGGACT", "TGTGTTTGTCGCCATG", "ACCAGTATCAGTTGAC", "TGGTTCCTCCGGGTGT",
"CTAGCCTCATACAGCT", "GCGAGAAGTTCACCTC", "GGAAAGCAGGATGTAT", "CATGCCTGTCGAGTTT",
"ACAGCCGTCCACGTTC", "TTTCCTCGTCTCCATC", "GCTTCCAGTGAAGGCT", "AGGGAGTTCGTTACGA",
"AGATCTGTCTCGTATT", "TGTTCCGCATCCCACT", "TGATTTCGTTACGACT", "CAGCCGAAGTCCGGTC",
"GCATACATCCCAACGG", "TCTGAGATCCGCATAA", "TTGGCAACATGCCACG", "GGTGAAGAGCTGATAA",
"TCGGGACCACTGTTAG", "TCAGATGGTCTTGTCC", "GGACAAGCACCGCTAG", "CAGATCATCCGTAGGC",
"CTCACACGTTCCGGCA", "CATCAAGGTGCAGACA", "TAGCCGGGTTAAGATG", "CCATGTCTCGATCCCT",
"ATTATCCCAGCCAATT", "GCCTCTAGTTGAGGTG", "CAAGAAAAGCTGTCTA", "CGTTGGGTCACCAGGC",
"CGTAGCGTCTTGAGAC", "AACGTTGGTTGCTCCT", "CATCCACGTGAGTATA", "TGAGGGACAATGGACG",
"CCAGCGAAGCTATGCT", "CGTTGGGTCACGGTTA", "ACTATCTGTAGCGTAG", "ATTTCTGCATGGTCAT",
"TACGGATGTCCTGCTT", "TGGTTCCCAGACGTAG", "GCAAACTGTAGCGTGA", "CCACGGAGTAACGACG",
"GGCCGATAGCGTTGCC", "GGTGCGTAGAAACCAT", "ACGATACGTTCTGAAC", "GACACGCTCCAAACTG",
"GCCTCTAGTTCAGTAC", "TCGAGGCGTGAGTATA", "TACTCGCCAGGATTGG", "GGGAATGTCTTCATGT",
"ACTTTCATCTATCCCG", "GTGCATAGTAAACCTC", "AAGTCTGCATTCTCAT", "TCGGTAATCCACGCAG",
"CAGCATAAGCCGTCGT", "GCTGGGTCACTAAGTC", "CTTACCGGTCTCATCC", "CGTCAGGCAAAGTCAA",
"ACGGAGATCCAAACTG", "GCATACAAGTAGCGGT", "GACTGCGCAGAAGCAC", "ACTGAGTAGTGATCGG",
"GAATGAATCGCGGATC", "CAAGTTGGTACTCGCG", "GATGCTAAGACTAGAT", "GATGCTATCAAACCAC",
"AAATGCCTCTTTACAC", "GTAGTCATCTGGTGTA", "TCACGAACAAGTTGTC", "TTGCCGTTCTAACGGT",
"CGGACTGAGTCCGTAT", "TGGACGCAGGAGTAGA", "TACCTTAGTACAGCAG", "TCGCGAGAGGTGCAAC",
"ACTGAACAGGTGGGTT", "GCACATATCCACGTTC", "AGTGAGGTCGTCCAGG", "GGGTTGCTCTACTCAT",
"CTCAGAAAGTGAACAT", "CTGTGCTTCAACGGCC", "ACGGCCACACCTTGTC", "TCTGAGACAAGAAAGG",
"CACAGGCAGTACACCT", "TCGGTAAAGATCCCGC", "TCATTACCATCACGTA", "ACATCAGGTGATGTCT",
"GACAGAGTCAGCTTAG", "CTACCCACAAACCTAC", "TTCTTAGTCTCTAGGA", "AAGCCGCGTTATCCGA",
"GTACGTAAGATGCCAG", "TTCGGTCGTCTCGTTC", "GTACGTATCCAATGGT", "TTATGCTAGACGACGT",
"CAGAATCTCACTCTTA", "ATTCTACTCGTTTAGG", "GCAAACTGTGGGTCAA", "GGGTCTGTCTGATACG",
"TTTGTCATCCTAAGTG", "GCTGCGAGTCGAGTTT", "GAATAAGAGCGTGTCC", "TCTCTAACACGGTAGA",
"GAATAAGCAAGTCTAC", "AACTTTCCAATGTAAG", "TAGACCATCCTAGGGC", "TGACTTTCAAGTACCT",
"AAAGCAAGTGATAAAC", "GGATTACGTCTTCAAG", "AGAGCTTGTAGAGTGC", "GCTGCTTGTGAGGGTT",
"GGCAATTAGCACCGTC", "TCAGGATGTAGCGTAG", "ACGAGCCGTTCCACTC", "GAACGGAAGAGACGAA",
"TACGGATGTCGGGTCT", "AGTTGGTTCCCGACTT", "AGCCTAATCGTTTGCC", "CAGTCCTAGTGTGGCA",
"CTGCGGAAGAGTAAGG", "CGAGCACCACCACGTG", "TTAACTCCATCAGTCA", "TTGCCGTCAAAGTCAA",
"GTACTCCTCGGATGGA", "AATCCAGTCCGGGTGT", "ATCTGCCGTCCGTGAC", "TACGGATCAATCCAAC",
"TGGCTGGGTTGATTGC", "CATCAAGGTCGCATCG", "AGCTCCTCAGCTTCGG", "CACACAATCAACACAC",
"TTCTACAAGCTGAAAT", "GACTGCGGTCAGCTAT", "TACAGTGCACATCCAA", "GACGTGCGTGCAGACA",
"GGACAAGTCTGCAGTA", "TAGGCATGTCAGTGGA", "CTTACCGTCGTAGGTT", "CGAGCACAGACAATAC",
"AGGTCATCAGTATAAG", "TGTTCCGTCTGCGTAA", "TCAGCAACATTCTCAT", "GTACTTTGTTCAGACT",
"TTGAACGCACCCATTC", "CAAGTTGGTAAGTGGC", "CAAGTTGAGTACGCGA", "CCTCTGAGTGTGCGTC",
"CCAGCGATCCAAGTAC", "ACTGATGGTAAAGGAG", "CTTAACTAGCTAGTCT", "ACACCAAAGTGGTCCC",
"ACTGAACGTCTACCTC", "AGTGGGAAGCGGATCA", "GTTACAGCATAGTAAG", "CAAGGCCAGAGGTTAT",
"TTTCCTCTCTACCAGA", "CTGTGCTGTCATCGGC", "CCTATTATCCTTGCCA", "TCAGGTAGTAGCTGCC",
"TTCTACACATTCGACA", "TGTGGTACATCACAAC", "CAGCGACGTACCGCTG", "AGTTGGTTCACTTCAT",
"TACTTGTAGCGTAATA", "TTAGTTCGTGTGCCTG", "TGTTCCGTCACCTCGT", "AACTGGTAGAGGTTGC",
"CACATAGTCAGCGATT", "CTGCTGTGTGACGGTA", "ACATACGCAATAACGA", "TAGTGGTCACGTTGGC",
"CTGAAACTCGCCTGAG", "ACTTACTAGTAGGTGC", "TCTGAGAAGGGTTCCC", "GTTTCTAGTGCACCAC",
"TCAGCTCAGCGATCCC", "AACGTTGCAAGGTGTG", "GAATGAACAAAGTCAA", "AAACGGGTCTTGAGGT",
"CCTTTCTTCAGGCAAG", "GGACAAGAGCTAAGAT", "GGCTGGTTCTTGCATT", "TGCGCAGAGCCAGTAG",
"CCACTACGTGTTGGGA", "TCAGGTAAGACGCTTT", "CCACCTACATGTCTCC", "GAACATCTCAGAGCTT",
"AGTCTTTTCCAAGCCG", "GATCGCGAGCTATGCT", "AACGTTGCAGCGAACA", "AACTGGTTCGTCCGTT",
"TTGCCGTGTTATGCGT", "TCAATCTTCCAACCAA", "GAGTCCGTCGGAAACG", "AACACGTGTCGCTTCT",
"TGGACGCAGAAGATTC", "GCTTCCATCTGTCAAG", "GGGCACTTCGATAGAA", "TGACTTTGTTCAGACT",
"GTGCGGTAGACACTAA", "CAGCATATCTACTATC", "TTGGCAATCGGGAGTA", "CAGAGAGTCTGTCCGT",
"AGAGCTTAGCCCAGCT", "TGGTTCCGTCTAACGT", "GCGGGTTTCTATCCCG", "TCACAAGAGCGTGAGT",
"TCCCGATAGATAGGAG", "TCTCTAATCGTATCAG", "CACCACTAGGGATGGG", "TAGACCAGTTCTGGTA",
"TCAGCTCGTTAGATGA", "TACGGATTCTAGAGTC", "GTCATTTAGTGGTAGC", "GTACTCCTCTGGCGTG",
"AATCCAGCAGGAACGT", "AGCAGCCGTGCAGGTA", "GAAATGATCAGGTAAA", "CCATGTCGTGGTACAG",
"CACCTTGAGCGCCTCA", "TTAGTTCAGTTCGCGC", "GTGTTAGCAGGAATGC", "GACTAACAGATGCGAC",
"TTGGCAACACTAGTAC", "GCTGCGAGTTGTGGCC")), x = c(1, 1, 1, 1, 4,
4, 2, 1, 1, 1, 5, 6, 2, 1, 4, 2, 3, 1, 5, 1, 9, 3, 1, 2, 3, 1,
2, 2, 1, 8, 8, 6, 6, 1, 5, 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 8,
2, 4, 2, 1, 1, 4, 2, 1, 2, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 3, 1,
1, 2, 5, 1, 1, 4, 1, 4, 3, 1, 1, 2, 4, 1, 2, 2,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,
6L, 8L, 3L, 4L, 1L, 5L, 8L, 4L, 6L, 8L, 5L, 8L, 3L, 5L, 7L, 8L,
6L, 5L, 8L, 2L, 8L, 8L, 3L, 5L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9"), class = "factor")
The issue is with the loop as it is creating some corrupted plots. Try this approach. Also use #GregorThomas suggestion:
#Values
n_clusters <- length(levels(SNF_W_louvain))
n_features <- dim(filtered_ADT_counts)[1]
Now, new code:
List <- list()
for(current_cluster in 1:n_clusters) {
#List
all_plots <- list()
#Loop
for(current_marker in 1:n_features) {
current_data <- data.frame(counts = filtered_ADT_counts[current_marker, SNF_W_louvain == current_cluster])
fit_poisson <- glm(counts ~ 1, current_data, family = "poisson")
fit_info <- paste0("AIC: ", round(fit_poisson$aic, 2), " (Pois)")
plot_title <- paste0("Protein: ", rownames(filtered_ADT_counts)[current_marker], " Cluster: ", current_cluster)
pred_density_pois <- dpois(current_data$counts, lambda = exp(fit_poisson$coefficients[1]))
current_plot <- current_data %>%
bind_cols(data.frame(pred_density_pois=pred_density_pois)) %>%
ggplot() +
geom_histogram(aes(x = counts, y=..density..), fill = "white", color='red') +
geom_line(aes(x = counts, y = pred_density_pois), color= 'blue') +
ggtitle(plot_title) +
annotate("text", x = Inf, y = Inf, hjust = 1, vjust = 2, label = fit_info, size = 3)
all_plots[[current_marker]] <- current_plot
}
List <- c(List,all_plots)
}
And export:
ggsave(
filename = "all_plots.pdf",
plot = marrangeGrob(List, nrow=4, ncol=2),
units = "mm",
width = 210,
height = 297
)
Let me know if that works as I do not have any output to compare.

non-numeric argument to binary operator - log()

When I try to run log(x) on a variable in my dataset I get the error:
Error in oldat$gdp16 + 1 : non-numeric argument to binary operator
At first I thought that the reason is that these particular variables have NA's so I decided to deal with this problem like so:
oldat$gdp16[oldat$gdp16 == "#N/A"] <- "NA"
oldat$gdp16LOG <- log(oldat$gdp16 + 1, na.rm=TRUE)
This did not solve the problem.
Please find the excerpt of the data as an example below. The variable that fails the log transform is gdp16:
structure(list(gdp16 = c("19469", "159049", "554861", "10546",
"1208039", "390800", "37868", "11839", "32153", "47723", "467546",
"15649", "1793989", "53241", "32218", "1535768", "250036", "11190993",
"280091", "51339", "NA", "20154", "195305", "306900", "72343",
"98614", "332928", "5010", "23338", "73001", "4671", "238678",
"2465134", "14014", "14378", "3477796", "192691", "1056", "68664",
"320881", "125817", "20304", "2274230", "932256", "418977", "304819",
"317748", "1859384", "36375", "14057", "4949273", "137278", "70875",
"6715", "110912", "6813", "27572", "42773", "296536", "12232",
"1076912", "6796", "11183", "4374", "103606", "777228", "189286",
"404653", "7607", "1414804", "371075", "57821", "304889", "27424",
"471400", "205184", "105035", "152452", "187806", "1284728",
"644936", "38300", "309764", "89769", "44709", "295763", "1411042",
"1237255", "95584", "514460", "668745", "NA", "525608", "6952",
"411755", "4389", "22320", "42063", "863722", "24079", "93270",
"357045", "2650850", "18624475", "67068", "236", "205276", "16620"
), pop16 = c(34656L, 40606L, 43847L, 2925L, 24211L, 8737L, 9758L,
391L, 1425L, 9502L, 11331L, 2250L, 207653L, 7128L, 23439L, 36265L,
17910L, 1378665L, 48653L, 4174L, 11476L, 1170L, 10566L, 5728L,
10649L, 16385L, 95689L, 4955L, 1316L, 102403L, 899L, 5495L, 66860L,
1980L, 3719L, 82349L, 10776L, 107L, 16582L, 7337L, 9814L, 335L,
1324171L, 261115L, 80277L, 4755L, 8546L, 60627L, 23696L, 2881L,
126995L, 17794L, 48462L, 1816L, 4053L, 6080L, 1960L, 2868L, 31187L,
1263L, 127540L, 3552L, 3027L, 622L, 35277L, 17030L, 4693L, 185990L,
20673L, 51246L, 5235L, 4034L, 103320L, 6725L, 37970L, 10325L,
3407L, 2570L, 19702L, 144342L, 32276L, 7058L, 5607L, 5431L, 2065L,
56015L, 25369L, 46484L, 39579L, 9923L, 8373L, 18430L, 22465L,
8735L, 68864L, 7606L, 1365L, 11403L, 79512L, 41488L, 45005L,
9270L, 65596L, 323406L, 31848L, 31568L, 94569L, 16150L), gold16 = c(0L,
0L, 3L, 1L, 8L, 0L, 1L, 1L, 1L, 1L, 2L, 0L, 7L, 0L, 0L, 4L, 0L,
26L, 3L, 5L, 5L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L,
10L, 0L, 2L, 17L, 3L, 0L, 0L, 0L, 8L, 0L, 0L, 1L, 3L, 0L, 0L,
8L, 1L, 6L, 12L, 3L, 6L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 8L, 4L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 2L, 0L, 1L, 0L,
1L, 19L, 0L, 2L, 1L, 2L, 1L, 2L, 9L, 7L, 0L, 2L, 3L, 0L, 1L,
1L, 2L, 0L, 0L, 0L, 1L, 0L, 2L, 0L, 27L, 46L, 4L, 0L, 1L, 0L),
tot16 = c(0L, 2L, 4L, 4L, 29L, 1L, 18L, 2L, 2L, 9L, 6L, 0L,
19L, 3L, 0L, 22L, 0L, 70L, 8L, 10L, 11L, 0L, 10L, 15L, 1L,
0L, 3L, 0L, 1L, 8L, 1L, 1L, 42L, 0L, 7L, 42L, 6L, 1L, 0L,
0L, 15L, 0L, 2L, 3L, 8L, 2L, 2L, 28L, 2L, 11L, 41L, 18L,
13L, 1L, 0L, 0L, 0L, 4L, 5L, 0L, 5L, 0L, 2L, 0L, 1L, 19L,
18L, 1L, 1L, 7L, 4L, 0L, 1L, 0L, 11L, 1L, 1L, 1L, 4L, 55L,
0L, 8L, 1L, 4L, 4L, 10L, 21L, 17L, 0L, 11L, 7L, 0L, 3L, 1L,
6L, 0L, 1L, 3L, 8L, 0L, 11L, 1L, 67L, 121L, 13L, 3L, 2L,
0L), altitude = c(1790, 1, 10.5, 989, 605, 170, -28, 2, 6,
198, 76, 983, 1079, 580, 726, 74, 521, 44, 2625, 130, 4,
170, 244, 0, 0, 2850, 22, 2325, 37, 2355, 0, 25, 34, 0, 451,
34, 153, 25, 1529, 100, 102, 15, 210, 3, 1189, 8, 754, 14,
217, 53, 17, 338, 1795, 0, 5, 771, 8, 124, 60, 134, 2240,
80, 1350, 61, 53, -2, 10, 777, 207, 6, 12, 0, 7, 54, 93,
15, 3, 13, 70, 124, 624, 116, 0, 131, 281, 1271, 33, 667,
377, 15, 542, 691, 5, 789, 1, 63, 0, 0, 938, 1190, 168, 13,
14, 2, 459, 909, 25, 1483), athletes16 = c(3L, 64L, 215L,
31L, 420L, 72L, 56L, 29L, 33L, 120L, 104L, 12L, 462L, 50L,
24L, 310L, 42L, 392L, 143L, 85L, 117L, 15L, 104L, 119L, 26L,
37L, 121L, 12L, 46L, 37L, 53L, 54L, 393L, 6L, 40L, 418L,
92L, 7L, 21L, 37L, 154L, 8L, 112L, 28L, 63L, 76L, 47L, 309L,
12L, 56L, 336L, 101L, 79L, 8L, 0L, 19L, 32L, 67L, 32L, 2L,
123L, 23L, 43L, 35L, 48L, 237L, 195L, 71L, 6L, 31L, 62L,
10L, 13L, 11L, 234L, 90L, 40L, 37L, 95L, 285L, 10L, 103L,
25L, 52L, 63L, 135L, 135L, 307L, 6L, 151L, 103L, 7L, 57L,
7L, 54L, 5L, 28L, 61L, 100L, 21L, 204L, 12L, 360L, 555L,
70L, 86L, 22L, 30L)), class = "data.frame", row.names = c(NA,
-108L))
Your gdp16 variable is of class character. You cannot add a number to character. You need to convert your variable to the numeric type (and perhaps substitute NAs):
df$gdp16 <- as.numeric(df$gdp16)
You need to replace the "NA" with an actual NA, and do as.numeric:
oldat$gdp16LOG = log(as.numeric(replace(oldat$gdp16,oldat$gdp16=="NA",NA)))
You can just do as.numeric(oldat$gdp16) . It will return some error messages because any other string that is not numeric will be converted to NA..

Connect geom_segment to geom_point outside the plot in ggplot?

I need help to connect a geom_segment to a geom_point outside the plot. I tried looking up answers to similar questions but that did not solve my problem.
I have a plot with two y-axes as shown below:
I need to add an orange point at (15, 120). As you can see, each orange dot is connected with an orange geom_segment. However, geom_segment cannot draw outside the plot. I tried adding coord_cartesian(ylim = c(0, 120), xlim = c(0,25), clip="off") but that did not help. Maybe it has something to do with the double-y-axis?
My script is the following and My data can be found below.
j <- ggplot() + theme_classic() +
geom_bar(mapping = aes(x = w$ki67pro[w$recurrence==1]), stat = "count", alpha=0.2, colour="#51BFC4", fill="#51BFC4")
yaks <- c(0,1,2,3,4,5,6,7,8,9)
j <- j %+% scale_y_continuous(expand=c(0,0), name = "XX", breaks=yaks, sec.axis = sec_axis(~ . * 1 , name = "YY", breaks=yaks, labels=c("0.000","0.025","0.050","0.075","0.100","0.125","0.150", "0.175","0.200", "0.225")), limits = c(0, 8.5))
j +
geom_point(mapping = aes(x = 0, y = 2.008368), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 1, y = 0.0000000), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 2, y = 1.0706320), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 3, y = 0.8202982), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 4, y = 1.1170213), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 5, y = 2.1384815), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 6, y = 0.0000000), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 7, y = 3.6090226), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 8, y = 6.6666667), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 10, y = 3.0868167), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 12, y = 1.5604681), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 15, y = 120.0000000), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 20, y = 8.0672269), size=2.5, shape=16, colour="#F0746B") +
geom_point(mapping = aes(x = 25, y = 0.0000000), size=2.5, shape=16, colour="#F0746B") +
geom_segment(mapping = aes(x = 0, y = 2.008368, xend = 1, yend = 0), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 1, y = 0, xend = 2, yend = 1.0706320), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 2, y = 1.0706320, xend = 3, yend = 0.8202982), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 3, y = 0.8202982, xend = 4, yend = 1.1170213), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 4, y = 1.1170213, xend = 5, yend = 2.1384815), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 5, y = 2.1384815, xend = 6, yend = 0.0000000), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 6, y = 0, xend = 7, yend = 3.6090226), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 7, y = 3.6090226, xend = 8, yend = 6.6666667), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 8, y = 6.6666667, xend = 10, yend = 3.0868167), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 10, y = 3.0868167, xend = 12, yend = 1.5604681), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 12, y = 1.5604681, xend = 15, yend = 120), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 15, y = 120, xend = 20, yend = 8.0672269), colour="#F0746B", alpha=1) +
geom_segment(mapping = aes(x = 20, y = 8.0672269, xend = 25, yend = 0), colour="#F0746B", alpha=1)
My data
w <- structure(list(recurrence = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L,
1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L,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 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 44L, 45L, 46L, 47L, 48L,
49L, 50L, 51L, 52L, 53L, 54L, 55L, 57L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 87L, 89L, 90L, 91L,
92L, 93L, 94L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L,
105L, 106L, 107L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L,
117L, 118L, 119L, 120L, 121L, 123L, 124L, 125L, 126L, 127L, 128L,
130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L,
141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L,
152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L,
163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L,
174L, 175L))
Don't set the limits with scale_*(). Set it with coord_*().
The first function (family) removes rows; the second functions zooms the perspective.
edit: This follows #teunbrand's comment. Replace the fourth line with
j <- j %+%
scale_y_continuous(
expand=c(0,0),
name = "XX",
breaks=yaks,
# limits = c(0, 8.5), # This is the undesirable specification
sec.axis = sec_axis(~ . * 1 , name = "YY", breaks=yaks, labels=c("0.000","0.025","0.050","0.075","0.100","0.125","0.150", "0.175","0.200", "0.225"))
) +
coord_cartesian(ylim=c(0, 8.5))

Resources