简体   繁体   English

ggplot2 中的图例标题

[英]Legend title in ggplot2

I am struggling to change legend title in ggpplot2.我正在努力更改 ggpplot2 中的图例标题。 The plot is produced with legend title saying "Enrichment_Score", and I want to change to "Enrichment Score".该情节的图例标题为“Enrichment_Score”,我想更改为“Enrichment Score”。

If anyone can advice would be brilliant.如果有人可以提出建议,那就太好了。

D1 <- ggplot(Practice, aes(Practice$case, Practice$pathway, 
      colour = Enrichment_score, size = Practice$q.value)) +
  geom_point() +
  scale_colour_gradientn(colours = cols) +
  theme(legend.position="bottom") +
  scale_size(range = c(1,15)) +
  guides(size=guide_legend(title = "FDR q value"),
         scale_color_gradient=guide_legend("Enrichment Score"))

 
D1 + ggtitle("Gene Set Enrichment Treg cells") +
  xlab("Case") + ylab("Hallmark Gene Sets") +
  theme_bw() ```

Treg cells Treg细胞

You can rename aesthetics in legends for example via the ggplot2 function labs like in the following reprex.例如,您可以通过 ggplot2 函数labs重命名图例中的美学,如下面的 reprex 所示。

library(ggplot2)

df <- data.frame(
  x = runif(100),
  y = runif(100),
  z1 = rnorm(100),
  z2 = abs(rnorm(100))
)

ggplot(df, aes(x, y)) +
  geom_point(aes(colour = z1)) +
  scale_colour_gradient2() +
  labs(colour = "My Legend Name")

reprex output再现输出

Created on 2021-10-13 by the reprex package (v2.0.1)reprex 包(v2.0.1) 于 2021 年 10 月 13 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM