首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正确使用geom_alpha_manual

正确使用geom_alpha_manual
EN

Stack Overflow用户
提问于 2020-02-04 05:55:35
回答 1查看 38关注 0票数 0

我有一些数据,比如虹膜数据集。

代码语言:javascript
复制
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值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-04 06:09:24

您还需要将Species映射到alphashape

代码语言:javascript
复制
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)))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60047718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档