英文:
How to change the size of stars in my plot by ggplot2?
问题
我想根据padj
值在我的图表上添加星号,但星号的大小太小了。我知道我是手动添加的,但我不知道如何在我的图表上使用更大的星号。
这是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))
而我的脚本如下:
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))
感谢任何帮助。
英文:
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.
答案1
得分: 1
你可以通过 `geom_text` 的 `size` 参数来设置标签的大小:
```r
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][1]][1]
<details>
<summary>英文:</summary>
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][1]][1]
[1]: https://i.stack.imgur.com/tN0ec.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论