gpt4 book ai didi

r - 控制 map 图例中的值范围

转载 作者:行者123 更新时间:2023-12-05 03:16:18 28 4
gpt4 key购买 nike

我想增加图中值的范围。在示例中,值的范围从 50 到 200。但是,我需要按如下方式分配值:50 75 100 125 150 175 200 并且最好使用 scale_fill_gradientn 函数,这可能吗?

volcano %>% reshape2::melt(varnames=c("x", "y")) %>% as_tibble() %>% 
ggplot(aes(x,y, fill=value)) + geom_tile() +
scale_fill_gradientn(colours=hcl.colors(15, palette = "Purple-Green"), limits=c(50,200))

最佳答案

我们可以使用 breakslabels 参数:

library(ggplot2)
volcano %>%
reshape2::melt(varnames=c("x", "y")) %>%
as_tibble() %>%
ggplot(aes(x,y, fill=value)) +
geom_tile() +
scale_fill_gradientn(colours=hcl.colors(15, palette = "Purple-Green"),
limits=c(50,200),
breaks = c(50,75,100,125, 150, 175, 200),
labels=c(50,75,100,125, 150, 175, 200))

enter image description here

关于r - 控制 map 图例中的值范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74718577/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com