2

I have made a chart with rectangles alpha depending on values:

ggplot(data = df_ch1,aes(IMPORTANCE, PERFORMANCE)) + geom_point(aes(size = N), alpha = 0.2) + facet_wrap(~Attitude, labeller = label_wrap_gen(30))+

  theme_light()+ labs(fill = "Classification")+
  theme(axis.text.x = element_text(angle=45, hjust = 1), #legend.position = 'none',
        strip.text  = element_text(size = 12, face = "bold"))+
  scale_size(range = c(5,10))+
  geom_text(aes(x = 1.5, y = 1.5,label =  label4))+
  geom_text(aes(x = 3.5, y = 3.5,label =  label1))+
  geom_text(aes(x = 3.5, y = 1.5,label =  label2))+
  geom_text(aes(x = 1.5, y = 3.5,label =  label3))+
  scale_x_discrete(labels = c("Very unimportant", "Somewhat unimportant", "Somewhat important", "Very Important"))+
  #geom_rect(aes(xmin = 2.55, xmax = 4.45, ymin=  0.55, ymax = 2.45,alpha = rect_color_dw1), fill = "darkred")+
  scale_alpha(range = c(0, 0.1),  breaks = (c(0, 0.2, 0.4, 0.6, 0.8, 1)), labels = percent(c(0, 0.2, 0.4, 0.6, 0.8, 1)/2)) +
  geom_rect(data = df_ch1, aes(xmin = 2.55, xmax = 4.45, ymin=  2.55, ymax = 4.45, alpha = rect_color_up1), fill  = 'darkgreen', inherit.aes = T) +
  labs(alpha = "Percentage")

It looks good:

enter image description here

However, when I add second rectangle (just uncomment comented line) scale legend switches to grayscale, which is completly nonintuitive: enter image description here

I want to have two alpha coloured scales (red and green). Is it possible to make it?

Best Regards Tomasz

markus
  • 25,843
  • 5
  • 39
  • 58
Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12
  • 1
    Could you maybe post some of your data (`dput(head(df_ch1,20))` or `dput(df_ch1)`) so that it is a bit easier to reproduce your problem? – Max Teflon Jul 09 '19 at 12:04
  • 1
    Isn't the green scale also completely nonintuitive? A second scale is not possible. Try to get all data in one scale. – Roman Jul 09 '19 at 12:27
  • 1
    It might be possible to do the same thing as suggested in the answer to this question - a way of creating the legends seperately and adding them into the final plot: https://stackoverflow.com/questions/39185291/legends-for-multiple-fills-in-ggplot – Andy Baxter Jul 09 '19 at 12:34

0 Answers0