ggplot两种颜色的单独的alpha比例

时间:2019-07-09 11:01:43

标签: r ggplot2 legend

我根据值制作了带有矩形alpha的图表:

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")

看起来不错:

enter image description here

但是,当我添加第二个矩形(只是未注释的注释线)时,比例图例切换为灰度,这完全是不直观的: enter image description here

我想要两个Alpha色标(红色和绿色)。有可能做到吗?

最佳问候 托马斯(Tomasz)

0 个答案:

没有答案