填充颜​​色=线条颜色的填充和空心形状 [英] Filled and hollow shapes where the fill color = the line color

查看:171
本文介绍了填充颜​​色=线条颜色的填充和空心形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点图中传达三种类型的信息。我可以使用颜色,形状和填充(我的实际数据有太多的点来有效地使用尺寸)。但是如果填充颜色与轮廓颜色相同,它会看起来最好。



我能得到的最接近的是:



pre $ data $ mtcars
p < - ggplot =(factor)(cyl),shape = factor(gear),fill = factor(vs)))+
scale_fill_manual(values = c(black,NA))+ scale_shape_manual(values = c(21,22, 23))


其中所有的轮廓颜色都是黑色,很丑。任何关于如何用红色和蓝色点填充红点的想法?

介绍 NA ,并使用 scale_fill_discrete 将映射到 NA 颜色:

  ggplot(mtcars,aes(x = mpg,y = wt))+ 
geom_point(size = 10,
aes (
color = factor(cyl),
shape = factor(gear),
fill = factor(ifelse(vs,NA,cyl))#<----注意这个
))+
scale_shape_manual(values = c(21,22,23))+
scale_fill_discrete(na.value = NA,guide =none)#< ---- NOTE这

生产:






编辑:为了解决Flick先生,我们可以作弊并添加图层/阿尔法。请注意,我们需要添加一个图层,因为据我所知,无法独立控制颜色和填充的Alpha:

  library(ggplot2)
ggplot(mtcars,aes(x = mpg,y = wt,color = factor(cyl),shape = factor(gear))+
geom_point(size = 10,aes fill = factor(cyl),alpha = as.character(vs)))+
geom_point(size = 10)+
scale_shape_manual(values = c(21,22,23))+
scale_alpha_manual(values = c(1= 0,0= 1))

< img src =https://i.stack.imgur.com/615wR.pngalt =在这里输入图片描述>


I want to convey three types of information in a dot-plot. I can use color, shape and fill (my actual data has too many points to use size effectively). But it would look best if the fill color was the same as the outline color.

The closest I can get is this:

data(mtcars)
p <- ggplot(mtcars,aes(x=mpg,y=wt))+
  geom_point(aes(color=factor(cyl),shape=factor(gear),fill=factor(vs)))+
  scale_fill_manual(values=c("black",NA))+scale_shape_manual(values=c(21,22,23))

which fills black into all outline colors, ugly. Any ideas on how to fill the red points with red and the blue points with blue?

解决方案

Introduce NA, and map those to the NA color with scale_fill_discrete:

ggplot(mtcars,aes(x=mpg,y=wt)) +
  geom_point(size=10,
    aes(
      color=factor(cyl), 
      shape=factor(gear), 
      fill=factor(ifelse(vs, NA, cyl))            # <---- NOTE THIS
  ) ) +
  scale_shape_manual(values=c(21,22,23)) +
  scale_fill_discrete(na.value=NA, guide="none")  # <---- NOTE THIS

Produces:


EDIT: To address Mr Flick, we can cheat and add layers / alpha. Note we need to add a layer because as far as I know there is no way to control alpha independently for color and fill:

library(ggplot2)
ggplot(mtcars,aes(x=mpg,y=wt, color=factor(cyl), shape=factor(gear))) +
  geom_point(size=10, aes(fill=factor(cyl), alpha=as.character(vs))) +
  geom_point(size=10) +      
  scale_shape_manual(values=c(21,22,23)) +
  scale_alpha_manual(values=c("1"=0, "0"=1))

这篇关于填充颜​​色=线条颜色的填充和空心形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆