r - ggplot 点中的轻微点描边

标签 r ggplot2

考虑以下:

图书馆(ggplot2)

df = data.frame(x = rep(0,9), y = rep(0,9), alp = c(1:8/20,1))
ggplot(df) + 
  geom_point(aes(x, y, alpha=alp), size = 20, col = 'red') + 
  theme_minimal() + facet_wrap(~ alp) + guides(alpha = F)

enter image description here

正如你所看到的,有虚幻的轮廓。它使叠加许多低透明度点看起来有点像 Frog 生成。这只是Mac的事情吗?知道如何删除它吗?

最佳答案

ggplot2 的默认点形状是 pch = 19 。它不是可以分别控制其边框和内部颜色的那些点之一;例如,在下面, fill = 'black' 不起作用。

library(ggplot2)

df = data.frame(x =runif(1000), y = runif(1000))

p = ggplot(df) + 
geom_point(aes(x, y), alpha = .1, size = 5, fill = 'black', colour = 'red') +                                        
  theme_bw() 
p

enter image description here

然而,这个点确实有一条边界线。线的宽度可以用 stroke 改变;如下:
p = ggplot(df) + 
geom_point(aes(x, y), stroke = 2, alpha = .1, size = 5, fill = 'black', colour = 'red') +                                        
  theme_bw() 
p

enter image description here

不幸的是,将stroke 设置为零不会删除边界线;似乎有一个下限。

要移除边界线,请使用具有可操作边界的形状之一;例如, shape = 21 。将其“填充”设置为红色,将其“颜色”设置为透明。
p = ggplot(df) + 
geom_point(aes(x, y), shape = 21, alpha = .1, size = 5, fill = 'red', colour = 'transparent') +                                      
  theme_bw() 
p

enter image description here

关于r - ggplot 点中的轻微点描边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38081159/

相关文章:

r - 更有效的声音文件二次采样方法?

r - 基于成功率填充的 stat_bin2d

r - ggplot 中的 ANCOVA 图

r - 将 ggplot2 标题映射到 dlply 调用中的变量

r - 为 facet_grid/facet_wrap 图的每一行分配唯一的宽度

r - 在 R 中的图中添加第二个图例

r - 使用 data.table 设置操作

r - ggplot2 geom_violin 的非常奇怪的图表

R时间序列数据: removing values from column that are less than previous value

r - 如何在ggplot2的顶部面板边框添加线条