Home > Enterprise >  why does geom_text_repel() ignore size aesthetic?
why does geom_text_repel() ignore size aesthetic?

Time:10-11

I am using geom_text_repel. Here is the code

xx <- structure(list(SYMBOL = c("HSPB1", "DSP", "COPA", "SEMA3B", "RFC1", 
"FAM120A", "MRPL24", "ENO1", "TAF15", "MRPL47", "MYO5A", "TTC37", 
"RBMX", "LEMD2", "GNL3", "TRMT2A", "EIF3H", "PSPC1", "MIOS", 
"POLR2A", "SCAMP3", "EEF2", "AGO3", "SASH1", "GTPBP4", "PARP1", 
"RPS3", "ATP2A2", "PPAN", "KPNB1", "SPATA5", "RPL18", "ARAP1", 
"VDAC2", "SF1", "RCN1", "NSUN5", "CSNK1A1", "PHGDH", "NAV1", 
"EIF4G1", "RSL1D1", "DHX29", "TCP1", "HSD17B12", "PLOD1", "AKAP8L", 
"STT3A", "DIMT1", "CCT5"), interactor = c(FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE), log2FC_OEIPtoOEC = c(-1.188, -1.071, -0.305, -1.196, 
-2.242, -1.083, -2.027, 0.101, -0.613, -1.195, -1.632, -0.934, 
-0.604, -1.714, -1.011, -1.301, -1.327, 0.447, -0.563, 0.061, 
0.159, -0.354, -0.696, 2.679, -2.407, -1.133, -1.174, -0.023, 
-1.739, 0.372, -1.84, -1.755, 2.496, 2.48, -0.13, -0.043, -1.436, 
-2.089, 0.601, -1.868, -0.587, -0.656, -0.689, 0.489, -0.389, 
-0.214, -0.682, -0.463, -2.124, -0.175), adj.pvalue_OEIPtoOEC = c(3.11820459104672e-06, 
0.000375326754978968, 0.000452267099086636, 2.29371074079822e-06, 
3.16069740512121e-08, 1.71482977276262e-09, 3.16164967556097e-09, 
0.803071498733443, 0.000260890847563963, 7.84919749378136e-08, 
2.81074102369284e-07, 0.000650750327476979, 1.76645936204616e-05, 
4.64727351507494e-07, 5.97431538613294e-08, 2.06414050372876e-06, 
1.60474719971609e-07, 1.06148995172679e-06, 0.000424624322200997, 
0.0822930476250642, 0.0669857879144555, 0.0497856508138053, 0.0010128186235129, 
6.79027171829534e-10, 7.08618519862231e-09, 5.31048502842373e-07, 
9.14238499256634e-06, 0.65661095803186, 0.000109268795075108, 
0.000896331917103447, 0.000154543207846778, 4.94297345832319e-06, 
1.74956073133704e-06, 6.14100266559054e-10, 0.0165759045939973, 
0.609835745607611, 3.22563881688616e-05, 2.36186291346976e-09, 
1.96827534532196e-06, 1.23996382790666e-06, 0.000563501819276639, 
6.07830082570168e-05, 0.000461083456429919, 0.0127703802958071, 
0.000553587826763665, 0.017917136749192, 1.08862548100969e-07, 
0.000666364393616902, 4.57980386379692e-08, 0.255896208213884
)), row.names = c(130L, 169L, 307L, 401L, 79L, 24L, 321L, 123L, 
69L, 506L, 59L, 402L, 14L, 309L, 362L, 531L, 481L, 181L, 499L, 
54L, 275L, 250L, 335L, 200L, 522L, 437L, 489L, 208L, 462L, 125L, 
367L, 536L, 331L, 161L, 344L, 294L, 508L, 249L, 220L, 412L, 82L, 
315L, 403L, 37L, 246L, 297L, 333L, 411L, 318L, 357L), class = "data.frame")

Here is the code for the plot

ggplot(xx, aes (log2FC_OEIPtoOEC, -log10(adj.pvalue_OEIPtoOEC), label = ifelse (interactor, SYMBOL, ""), colour = interactor))   
  geom_point()   
  geom_text_repel (aes(size = 100))   
  geom_hline(yintercept= -log10 (0.05), linetype="dashed")   
  geom_vline(xintercept= 1, linetype="dashed")   
  xlab ("Log2 fold change of IP to control")   
  ylab ("-Log10 of adjusted p-value")   theme_classic()

ggplot(xx, aes (log2FC_OEIPtoOEC, -log10(adj.pvalue_OEIPtoOEC), label = ifelse (interactor, SYMBOL, ""), colour = interactor))   
  geom_point()   
  geom_text_repel (aes(size = 0.01))   
  geom_hline(yintercept= -log10 (0.05), linetype="dashed")   
  geom_vline(xintercept= 1, linetype="dashed")   
  xlab ("Log2 fold change of IP to control")   
  ylab ("-Log10 of adjusted p-value")   theme_classic()

in the two plots, the aes for geom_text_repel specifies size as 100 and 0.01 respectively. However, this parameter is basically ignored and the text is always the same size, and a "size" box is added to the legend for some reason

figure

CodePudding user response:

To specify a literal size, rather than a variable that should be mapped to it, you remove the aes to get:

ggplot(xx, aes (log2FC_OEIPtoOEC, -log10(adj.pvalue_OEIPtoOEC), label = ifelse (interactor, SYMBOL, ""), colour = interactor))   
  geom_point()   
  geom_text_repel (size = 100)   
  geom_hline(yintercept= -log10 (0.05), linetype="dashed")   
  geom_vline(xintercept= 1, linetype="dashed")   
  xlab ("Log2 fold change of IP to control")   
  ylab ("-Log10 of adjusted p-value")   theme_classic()
  • Related