我有一些数据,比如虹膜数据集。
data(iris)
ggplot(data=iris,aes(x=Sepal.Length, y=Sepal.Width, color = Species, fill = Species)) + geom_point()我用Species对数据进行着色和填充。如何正确使用geom_alpha_manual()将setosa设置为alpha = 0.2,将versicolor设置为alpha = 0.5,将virginica设置为alpha = 0.8
或者,如何还可以使用scale_shape_manual(..., values)根据Species设置不同的形状
我可以使用scale_fill_manual(values = c("blue", "red", "green")和scale_color_manual(values = c("blue", "red", "green"),但我不太确定如何设置不同的Alpha值。
发布于 2020-02-04 06:09:24
您还需要将Species映射到alpha和shape。
library(ggplot2)
ggplot(data = iris,
aes(
x = Sepal.Length,
y = Sepal.Width,
color = Species,
fill = Species,
shape = Species,
alpha = Species
)) +
geom_point() +
scale_fill_manual(values = c("blue", "red", "green"),
aesthetics = c("colour", "fill")) +
scale_alpha_manual(values = c(setosa = .2,
versicolor = .5,
virginica = .8)) +
scale_shape_manual(values = 1:3) +
# optional guide adjustments below
guides(color = guide_legend(override.aes = list(alpha = 1,
size = 3)))

https://stackoverflow.com/questions/60047718
复制相似问题