ggplot2:geom_point的边框和填充使用不同的Alpha值 [英] ggplot2: different alpha values for border and filling of geom_point

查看:1668
本文介绍了ggplot2:geom_point的边框和填充使用不同的Alpha值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用geom_point将数据绘制成点图。我的数据点重叠,因此我想使用抖动和透明度来增加可见性。现在,我还要在每个数据点上添加边框,以使读者更容易看到每个数据点。但是,由于存在Alpha,我的数据点似乎周围有光晕。这就是为什么我只想对填充使用alpha,对边框使用alpha = 0的原因。但是到目前为止,我还没有找到解决方案。我可以绘制两个geom_point,一个比另一个大,以在每个点周围创建一个带有alpha = 0的边界。但是因为我需要抖动,所以相同的数据点不会相互重叠。
有谁知道如何解决这个问题吗?

I want to plot my data as a dotplot using geom_point. My datapoints are overlapping, so I want to use jitter and transparency to increase visibility. Now I would also like to add a border to every datapoint to make it even more easier for the reader to see each datapoint. However, due to the alpha, it looks like my datapoints have halos around them. That's why I would like to use alpha only for the filling and alpha=0 for the border. But so far I haven't found a solution. I could plot two geom_points one being slightly larger than the other to create a border around each point with alpha=0. But becuase I need jitter, the same datapoints won't lie on top of each other. Does anyone has an idea how to solve this problem?

这是我的代码:

ggplot(data=comp24, aes(x=spatial, y=lnfit, colour=spatial, fill=spatial, shape=spatial, backgroundColor="white", na.rm=T))+
geom_point(position=position_jitter(w=0.5), size=1.75, alpha=0.2, stroke=0.3)+
scale_colour_manual(name="spatial structure", values = c("black", "black", "black"))+
scale_fill_manual(name="spatial structure", values = c("black","black", "black"))

和一些数据:

spatial focal competitor       lnfit
low   pco        pch -1.79175947
low   pco        pch -1.49165488
low   pco        pch -0.98082925
low   pco        pch -1.97716269
intermediate   pco        pch -0.84729786
intermediate   pco        pch -0.48379695
intermediate   pco        pch -0.64574494
intermediate   pco        pch -0.51082562
intermediate   pco        pch  1.43693809
high   pco        pch  0.89608802
high   pco        pch  0.04879016
high   pco        pch -2.20625398
high   pco        pch  0.31003898
high   pco        pch -0.01694956

这是图形的详细信息,显示了我在说的光环。我猜它来自填充和边框重叠。这就是为什么我在灰色区域看到这条垂线。不幸的是,更改笔触值只会增加光晕效果。

Here is a detail of the graph, that shows the halo I am talking about. I guess it comes from filling and border overlapping a bit. That's why I see this draker line within the grey area. Changing the stroke value unfortunately only increases the halo effect.

我保存了我的图形为.tif,具有:

I save my graphs as .tif with:

tiff('C:/_..._..._.tif', bg = "white", res = 1600, width = 115, height = 160, units = "mm", compression="lzw")

期待您的建议。

欢呼声
Anne

Cheers Anne

推荐答案

这应该对您有用:

ggplot(data=comp24, aes(x=spatial, y=lnfit, colour=spatial, fill=spatial, shape=spatial, backgroundColor="white", na.rm=T))+
geom_point(position=position_jitter(w=0.5), size=1.75, stroke=0.3)+
scale_colour_manual(name="spatial structure", values = c("black", "black", "black"))+
scale_fill_manual(name="spatial structure", values =alpha(c("black","black", "black"),0.2))

让我知道

这篇关于ggplot2:geom_point的边框和填充使用不同的Alpha值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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