在ggplot2中添加边框或背景以缩放图例guide_colorbar [英] Adding border or background to scale legend guide_colorbar in ggplot2

查看:1051
本文介绍了在ggplot2中添加边框或背景以缩放图例guide_colorbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a colorbar within ggplot graph ranging from white to red and the white border is not very good visible on the white background.

是否可以通过其他方式为图例中的刻度线着色或在渐变比例周围添加边框?

Is there a way to color the tick marks in the legend differently or adding a border around the gradient scale?

这是一个最小的示例:

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')

推荐答案

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

In the latest ggplot2 (development version, to be released as 2.3), this now works:

# 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"))

这篇关于在ggplot2中添加边框或背景以缩放图例guide_colorbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆