The*_*aya 4 plot r opacity ggplot2
我想在我的情节和遇到的那几个改进alpha
的geom_segment
工作不正常。对于最小工作示例,请检查:
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
geom_segment(aes(x = 100, xend = 200, y = 20, yend = 20),
inherit.aes = FALSE,
size = 10,
alpha = 0.5,
color = "blue")
Run Code Online (Sandbox Code Playgroud)
但是,如果您将 alpha 更改为非常低的值,例如 0.005,则 0.001 似乎有效。您只能看到 0.05 到 0.001 之间的一些效果。
alpha 值不是应该在 0 和 1 之间以线性方式变化还是我理解不正确?
像这样的事情,
# install.packages(c("tidyverse"), dependencies = TRUE)
library(tidyverse)
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
annotate('segment', x = 100, xend = 200, y = 20, yend = 20,
size = 10,
alpha = 0.5,
color = "blue")
Run Code Online (Sandbox Code Playgroud)
ggplot2 正在绘制许多段,一个在彼此之上使段不透明。您可以通过data
从 ggplot 函数中删除并将其添加到所需图层来解决它。此处和此处与其他 geoms 的类似问题。
ggplot() +
geom_point(data=mtcars, aes(hp, mpg)) +
geom_segment(aes(x = 100, xend = 200, y = 20, yend = 20),
inherit.aes = FALSE,
size = 10,
alpha = 0.5,
color = "blue")
Run Code Online (Sandbox Code Playgroud)
另一种选择是像 Eric 一样使用 annotate:
ggplot(mtcars) +
geom_point(aes(hp, mpg)) +
annotate(
'segment',
x = 100,
xend = 200,
y = 20,
yend = 20,
size = 10,
colour = "blue",
alpha = 0.5
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2974 次 |
最近记录: |