1

An extension to this query, I have generated the plot using the approach suggested by eipi10.

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

Similarly, I have tried to change mappings to other aesthetic values such as alpha, shape:

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

but, it did not fetch the desired output (decrease transparency to hollow circles for Other points).

Prradep
  • 5,506
  • 5
  • 43
  • 84

1 Answers1

2

You have to specify alpha=Val & shape=Val in your aesthetics mapping.

I also changed the range of values for shape from c(rep(1,n),1) to c(rep(1,n),2), so that there's difference between the first 2 values & others.

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

(For info, the original colours I used were red & blue, as sampling the dark palette returned me virtually undistinguishable dark green & dark blue...)

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • I want same values for shapes and alpha to the values in `Val`. The changes are only intended for `Other` points. – Prradep Aug 30 '17 at 10:47
  • @Prradep edited my answer. By the way varying alpha won't hollow-ify a point. If you want solid vs hollow circles, you can use `values = c(rep(16,n),1)` in the scale_shape. – Z.Lin Aug 30 '17 at 10:56
  • Yes, thanks. I noticed the error and applied your solution. Will edit the question now. – Prradep Aug 30 '17 at 11:04