gpt4 book ai didi

r - 在ggplot2中添加边框或背景以缩放图例guide_colorbar

转载 作者:行者123 更新时间:2023-12-04 13:26:44 72 4
gpt4 key购买 nike

我在ggplot图表中有一个颜色条,范围从白色到红色,白色边框在白色背景上不太好看。

有没有办法为图例中的刻度线涂上不同的颜色或在渐变比例周围添加边框?

这是一个最小的示例:

df <- data.frame(x <- rnorm(10),
y <- rnorm(10),
fill <- rnorm(10))

ggplot(df, aes(x, y, fill = fill)) +
geom_point() +
scale_fill_gradient(low = 'white', high = 'red')

enter image description here

最佳答案

在最新的ggplot2(开发版本,将以2.3版本发布)中,现在可以使用:

# devtools::install_github("tidyverse/ggplot2") # do this once
library(ggplot2)
df <- data.frame(x <- rnorm(10),
y <- rnorm(10),
fill <- rnorm(10))

ggplot(df, aes(x, y, fill = fill)) +
geom_point() +
scale_fill_gradient(low = 'white', high = 'red',
guide = guide_colorbar(frame.colour = "black", ticks.colour = "black"))

enter image description here

关于r - 在ggplot2中添加边框或背景以缩放图例guide_colorbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29793398/

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