将映射添加到审美价值的有效方法

时间:2017-08-30 10:33:54

标签: r ggplot2

this query的扩展名,我使用eipi10建议的approach生成了地图。

valsToKeep <- c("D_1","D_4")
n <- length(valsToKeep)
getPaletteDark = brewer.pal(8,"Dark2")
colSel <- sample(getPaletteDark,n)

ggplot(df %>% 
         mutate(Val=fct_other(Val,keep=valsToKeep)) %>% 
         arrange(Val) %>% 
         filter(!duplicated(.[,c("X","Y")])), 
       aes(X,Y,col=Val)) + 
  geom_point() +
  scale_colour_manual(values=c(colSel,"grey70")) +
  theme_bw() 

enter image description here

同样,我尝试将映射更改为其他美学价值,例如alphashape

ggplot(df %>% 
         mutate(Val=fct_other(Val,keep=valsToKeep)) %>% 
         arrange(Val) %>% 
         filter(!duplicated(.[,c("X","Y")])), 
       aes(X,Y,col=Val)) + 
  geom_point() +
  scale_colour_manual(values=c(colSel,"grey70")) +
  scale_alpha_manual(values = c(rep(1,n),0.2)) +
  scale_shape_manual(values = c(rep(16,n),1)) +
  theme_bw() 

enter image description here

但是,它没有获取所需的输出(将透明度降低到Other点的空心圆)。

1 个答案:

答案 0 :(得分:2)

您必须指定alpha=Val&amp;在你的美学绘图中shape=Val

我还将形状的值范围从c(rep(1,n),1)更改为c(rep(1,n),2),以便前两个值和&amp;之间存在差异。其他

ggplot(df %>% 
         mutate(Val=forcats::fct_other(Val,keep=valsToKeep)) %>% 
         arrange(Val) %>% 
         filter(!duplicated(.[,c("X","Y")])), 
       aes(X,Y,col=Val,alpha=Val,shape=Val)) + 
  geom_point(size = 3) +
  scale_colour_manual(values=c(colSel,"grey70")) +
  scale_alpha_manual(values = c(rep(1,n),0.2)) +
  scale_shape_manual(values = c(rep(1,n),2)) +
  theme_bw() 

plot

(有关信息,我使用的原始颜色是红色和蓝色,因为黑色调色板的采样使我几乎无法区分深绿色和深蓝色......)

相关问题