Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在ggplot2中按组修改alpha值_R_Ggplot2 - Fatal编程技术网

R 在ggplot2中按组修改alpha值

R 在ggplot2中按组修改alpha值,r,ggplot2,R,Ggplot2,我想改变alpha刻度,现在我认为它是从0到1。 我想把它从0.2调整到0.5左右,因为这样我们看不到事件填充的颜色,M太暗,M1太亮 以下是数据库信息: > str(st2) 'data.frame': 24 obs. of 6 variables: $ Outcome : Factor w/ 4 levels "LGiT","LGuT",..: 3 3 3 1 1 1 2 2 2 4 ... $ Event : Factor w/ 3 levels "Event

我想改变alpha刻度,现在我认为它是从0到1。 我想把它从0.2调整到0.5左右,因为这样我们看不到事件填充的颜色,M太暗,M1太亮

以下是数据库信息:

> str(st2)

'data.frame':   24 obs. of  6 variables:
 $ Outcome   : Factor w/ 4 levels "LGiT","LGuT",..: 3 3 3 1 1 1 2 2 2 4 ...
 $ Event     : Factor w/ 3 levels "Event 1","Event 2",..: 1 2 3 1 2 3 1 2 3 1 ...
 $ Percentage: num  10.31 8.25 81.44 12.77 15.32 ...
 $ Method    : Factor w/ 2 levels "M1","M2": 1 1 1 1 1 1 1 1 1 1 ...
 $ Cohort    : Factor w/ 1 level "Cohort 1": 1 1 1 1 1 1 1 1 1 1 ...
 $ label     : chr  "10%" "8%" "81%" "13%" ...
 $ sum       : chr  "100.00%" "100.00%" "100.00%" "100.00%" ...
以下是绘图代码:

p7<-ggplot(st2, aes(x = factor(st2$Outcome:st2$Method), y = st2$Percentage,  
                fill = st2$Event, group=st2$Event)) +
  geom_bar(aes(alpha=st2$Method),position = position_stack(), stat = "identity", width = .7, colour="black") +
  geom_text(aes(label = st2$label), position = position_stack(vjust = 0.5),size = 4) + coord_flip() 


p8<-p7+labs(x="Outcome", y="Percentage Values", fill="Legend")+ scale_fill_grey(start=1, end=0.8)+ theme(axis.text=element_text(size=15), axis.title=element_text(size=17, face="bold"), legend.title=element_text(size=13), legend.text=element_text(size=12))


p8+theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
但它不起作用:错误:离散值提供给连续刻度


谢谢!

尝试使用
scale\u alpha\u discrete(range=c(0.2,0.5))
这很好!谢谢!是否可以通过方法添加类似点图案的图案?(M1带点,M2不带点)据我所知,这在ggplot2中是不可能的-它只进行素色填充。我确信有人找到了使用纹理填充的方法,但我怀疑它是否简单!不过,我认为在R的基础图形中是可能的。下面是一个解释,也是一个绕过它的英勇尝试。。。
scale_alpha(limits=c(0.2,0.5))