更改堆积条形图中的空格

时间:2018-05-31 21:27:15

标签: r ggplot2

是否可以减少第1和第2条,第3和第4,第5和第6,第7和第8条之间的空间,并置具有相同结果和不同方法的条形图。 这是数据库信息:

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

这是我的情节:

enter image description here

谢谢!

0 个答案:

没有答案