将ggplot2 colourbar刻度标记更改为黑色 [英] Change ggplot2 colourbar tick marks to black
问题描述
在我的一些情节中,我发现很难在颜色栏中看到刻度线。我还没有找到记录方式来改变滴答的颜色。所有的例子似乎都集中在改变标签或根本不绘制刻度。
#Data
require(ggplot2)
require(grid)
n < - 100
x <-y < - seq(-4 * pi,4 * pi,len = n)
r <-cos(sqrt(outer(x ^ 2,y ^ 2 ,x = rep(x,each = n),y = rep(y,times = n),val = c(r))
#Plot
ggplot(df,aes(x,y,fill = val))+
geom_raster()+
scale_fill_gradient(low =#FFFFFF ,高=#de2d26)+
指南(fill = guide_colourbar(barheight = unit(3,in))+
theme_bw()+
theme(line = element_line color =#0000FF))
我怎样才能让色板上的嘀嗒声被绘制成黑色而不是白色,而不改变剧情的其他元素?
ps对于创建示例数据的函数 此问题 的赞誉$ b $我通常通过广泛使用 str
来找到我需要改变的地方。
g < - ggplotGrob(p)
g $ grobs [ $ grobs [[5]] $ gp $ col< - black
library(grid)
grid.draw [8]] [[1]] [[1] (g)
In some of my plots I find it hard to see the tick marks in the colour bar. I haven't been able to find a documented way to change the colour of the ticks. All the examples seem to focus on changing the labels or not drawing ticks at all. Is it possible?
# Data
require(ggplot2)
require(grid)
n <- 100
x <- y <- seq(-4*pi, 4*pi, len=n)
r <- cos( sqrt( outer(x^2, y^2, "+") ) ^ 2 )
df <- data.frame( x = rep( x , each = n) , y = rep( y , times = n ) , val = c(r) )
# Plot
ggplot( df , aes( x , y , fill = val ) )+
geom_raster()+
scale_fill_gradient( low = "#FFFFFF" , high = "#de2d26" )+
guides( fill = guide_colourbar( barheight = unit( 3 , "in" ) ) )+
theme_bw()+
theme( line = element_line( colour = "#0000FF" ) )
How can I make the ticks in the colourbar be plotted in black rather than white, without changing other elements of the plot?
p.s. kudos to this question for the function to create the example data
I usually find what I need to change by extensive use of str
. I'm sure others can do it more elegantly.
g <- ggplotGrob(p)
g$grobs[[8]][[1]][[1]]$grobs[[5]]$gp$col <- "black"
library(grid)
grid.draw(g)
这篇关于将ggplot2 colourbar刻度标记更改为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!