ggplot点中的轻微点笔触 [英] Slight point strokes in ggplot points
问题描述
请考虑以下内容:
库(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)
如您所见,有一些模糊的轮廓.它使覆盖许多低透明度的点看起来有点像frogspawn.这只是Mac的东西吗?知道如何删除它吗?
As you can see there are feint outlines. It makes overlaying many low-transparency points look a bit like frogspawn. Is this just a Mac thing? Any idea how to remove it?
推荐答案
ggplot2的默认点形状为 pch = 19
.这不是可以单独控制其边框颜色和内部颜色的要点之一;例如,在下文中, fill ='black'
无效.
The default point shape for ggplot2 is pch = 19
. It's not one of those points where the colour of its border and its inside can be controlled separately; for instance, in the following, fill = 'black'
has no effect.
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
但是该点确实具有边界线.线的宽度可以用 stroke
更改;如下:
Yet the point does have a boundary line. The line's width can be changed with stroke
; as follows:
p = ggplot(df) +
geom_point(aes(x, y), stroke = 2, alpha = .1, size = 5, fill = 'black', colour = 'red') +
theme_bw()
p
不幸的是,将笔划设置为零不会删除边界线.似乎有一个下限.
Unfortunately, setting stroke to zero will not remove the boundary line; it seems there is a lower limit.
要删除边界线,请使用具有可操纵边界的形状之一;例如, shape = 21
.将其填充"设置为红色,将其颜色"设置为透明.
To remove the boundary line, use one of the shapes that has a border that can be manipulated; for instance, shape = 21
. Set its "fill" to red and its "colour" to transparent.
p = ggplot(df) +
geom_point(aes(x, y), shape = 21, alpha = .1, size = 5, fill = 'red', colour = 'transparent') +
theme_bw()
p
这篇关于ggplot点中的轻微点笔触的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!