你如何使geom_points透明化
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了你如何使geom_points透明化相关的知识,希望对你有一定的参考价值。
我有这个情节,当group2 = 0时,我将点的大小设置为0,将alpha设置为.000000000001,因为我想让这些点不可见。但你仍然可以看到图表上的圆圈。知道如何让那个圆圈完全隐形吗?
library(ggplot2)
dat = data.frame(label = c("A","B","C","D"), group1 = c(1,2,3,.02), group2 = c(3,4,5,0), color1 = c("lightblue","lightblue","lightblue","lightblue") ,
color12 = c("blue","blue","blue","blue"))
dat$sizze = ifelse(dat$group2 ==0 ,0, 2 )
dat$alpha = ifelse(dat$group2 ==0 ,0.0000000000001, 1 )
p1 <- ggplot(dat, aes(x = label, y = group1, fill = color1))+
geom_bar(stat="identity") +
geom_point(data = dat, aes(x = label, y = group2, color = color12, size = sizze, alpha = alpha))
p1 +
scale_size(guide='none', range=c(2) ) +
scale_fill_manual(values = c('lightblue' = 'lightblue'),
name = 'bar legend')+
scale_colour_manual(values = c('blue' = 'blue'),
name = 'point legend')
答案
如果您试图不绘制您的观点,最好只将geom_point
中的数据进行子集化。你可以尝试将你的geom_point
改为:
geom_point(data = dat[!(dat$group2==0),], aes(x = label, y = group2,
color = color12, size = sizze, alpha = alpha))
给出这个情节:
以上是关于你如何使geom_points透明化的主要内容,如果未能解决你的问题,请参考以下文章