Home > Mobile >  How to change the size of stars in my plot by ggplot2?
How to change the size of stars in my plot by ggplot2?

Time:01-09

I want to add stars to my plots based on padj values, but the of stars are too small. I know that I added them manually but I don't know how to have bigger stars on my plots.

Here is df

dput(df)

structure(list(CancerType = c("BRCA", "COAD", "LUAD", "LUSC", 
"STAD", "THCA", "UCEC", "ESCA", "KIRC", "PRAD", "LIHC", "GBM", 
"BLCA"), log2FC = c(-0.145366946, -0.276093973, 0.056591306, 
0.150671917, 0.159516768, 0.040044405, -0.050525831, -0.09909923, 
0.125670677, -0.131356051, 0.090115912, -0.170939552, -0.150633173
), padj = c(0.002552355, 0.001254905, 0.515358544, 0.119809051, 
0.117073154, 0.407311464, 0.595674904, 0.643894805, 0.029380174, 
0.014769961, 0.251602611, 0.470002204, 0.228163654)), class = "data.frame", row.names = c(7L, 
23L, 39L, 55L, 71L, 87L, 103L, 119L, 135L, 151L, 167L, 183L, 
199L))

And my script is here

nudge <- 0.02
x |> 
  mutate(
    sig_label = case_when(
      padj < 0.001 ~ "***",
      padj < 0.01 ~ "**",
      padj <= 0.05 ~ "*",
      padj > 0.05 ~ ""
    ),
    label_position = ifelse(log2FC > 0, log2FC   nudge, log2FC - (nudge 0.01))
  ) |> ggplot(aes(x = CancerType,y = log2FC)) 
  geom_bar(position="stack", stat="identity", fill='#38357A') 
  theme_bw() 
  theme(axis.text.x = element_text(size = 8, angle = 45, hjust = 1, colour = 'black')) 
  geom_text(aes(label = sig_label, y = label_position))

Thanks for any help.

CodePudding user response:

You could set the size for your labels via the size argument of geom_text:

library(dplyr)
library(ggplot2)

nudge <- 0.02

x |>
  mutate(
    sig_label = case_when(
      padj < 0.001 ~ "***",
      padj < 0.01 ~ "**",
      padj <= 0.05 ~ "*",
      padj > 0.05 ~ ""
    ),
    label_position = ifelse(log2FC > 0, log2FC   nudge, log2FC - (nudge   0.01))
  ) |>
  ggplot(aes(x = CancerType, y = log2FC))  
  geom_bar(position = "stack", stat = "identity", fill = "#38357A")  
  theme_bw()  
  theme(axis.text.x = element_text(size = 8, angle = 45, hjust = 1, colour = "black"))  
  geom_text(aes(label = sig_label, y = label_position), size = 16)

enter image description here

  • Related