0

I would like to change alpha scale, now I think it's from 0 to 1. I would like to make it from 0.2 to 0.5 or so..'cause in this way we can't see Event filling colours very well..M" is too dark and M1 too light..

Here's the database infos:

> 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%" ...

Here's the plot code:

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

Here is my plot:

enter image description here I've tried by adding

scale_alpha(limits=c(0.2,0.5))

but it doesn't work: Error: Discrete value supplied to continuous scale

Thank you!

ArTu
  • 431
  • 4
  • 20
  • 3
    Try using `scale_alpha_discrete(range = c(0.2, 0.5))` – Andrew Gustar May 31 '18 at 16:19
  • This works great! Thank you! – ArTu May 31 '18 at 21:12
  • Is it possible to add a pattern like a dot pattern by method? (M1 with dots and M2 without) – ArTu May 31 '18 at 21:14
  • As far as I know, that is not possible with ggplot2 - it just does plain coloured fills. I'm sure somebody has found a way of using textured fills, but I doubt it is straightforward! I think it is possible in R's base graphics, though. – Andrew Gustar May 31 '18 at 21:21
  • Here is an explanation and a heroic attempt to get round it... https://stackoverflow.com/q/2895319/7727429 – Andrew Gustar May 31 '18 at 21:27
  • Thank you Andrew, I saw this thred but I think it is a bit beyond my capabilities..Is it possible to change borders thickness by method? I'm afraid this plot is not so clear..but I don't know how to make it more explicit.. – ArTu May 31 '18 at 21:59
  • Yes, just add a `size` argument to your `geom_bar`, either fixed or as an aesthetic (in which case you might also want a `scale_size_discrete` term) – Andrew Gustar May 31 '18 at 23:11
  • I otbain this: Warning message: Using size for a discrete variable is not advised. – ArTu Jun 01 '18 at 14:22
  • It is just a warning. You can ignore it as long as the chart is doing what you want. – Andrew Gustar Jun 01 '18 at 14:38
  • ok, thank you! Can I ask something more? Can i reduce the space between 1st and 2nd bars, 3rd and 4th bars etc? – ArTu Jun 01 '18 at 15:39
  • Not directly. The best way would be to use `Method` as your `x` variable, and to then facet by `Outcome` by adding a term like `+facet_grid(Outcome~.)` – Andrew Gustar Jun 01 '18 at 15:54
  • Thank you Andrew, I hoped there was another way. – ArTu Jun 01 '18 at 18:16

0 Answers0