R GG为两种颜色绘制单独的alpha比例

R GG为两种颜色绘制单独的alpha比例,r,ggplot2,legend,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 = el

我已经制作了一个带有矩形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")
看起来不错:

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

我想要两个阿尔法色的刻度(红色和绿色)。有可能吗

致意
Tomasz

你可以发布一些数据(
dput(head(df_ch1,20))
dput(df_ch1)
)以便更容易再现你的问题吗?绿色刻度不是也完全不直观吗?第二个刻度是不可能的。尝试在一个比例中获取所有数据。可能可以按照此问题答案中的建议执行相同的操作-分别创建图例并将其添加到最终绘图中: