如何修复r

时间:2017-11-15 13:11:58

标签: r ggplot2 multiple-columns facet-wrap

我想用多个面板绘制多个数字。

我拥有的数据结构

quality organism      component   group value   se
Rho(-)  Phytoplankton   C16.1     MUFA  0.022336602 0.001715501
Rho(-)  Phytoplankton   C16.2n4   PUFA  0           0
Rho(-)  Phytoplankton   C16.3n4   PUFA  0.001106097 0.00096191
Rho(-)  Phytoplankton   C18.0     SFA   0.022975838 0.01324553
Rho(-)  Phytoplankton   C18.1n9t  MUFA  0.01571751  0.02271655
Rho(-)  Phytoplankton   C18.1n9c  MUFA  0.040262837 0.02746583
Rho(-)  Phytoplankton   C18.1n7   MUFA  0.080077945 0.01098649
Rho(-)  Phytoplankton   C18.2n6t  PUFA  0.005644246 0.00265683
Rho(-)  Phytoplankton   C18.2n6c  PUFA  0.098402341 0.03755471
Rho(-)  Phytoplankton   C18.3n6   PUFA  0.013530465 0.002457633
Rho(-)  Phytoplankton   C18.3n3   PUFA  0.262319627 0.03994807
Rho(-)  Phytoplankton   C20.0     SFA   0           0
Rho(-)  Phytoplankton   C20.1n9c  MUFA  0.000171337 0.000296765
Rho(-)  Phytoplankton   C20.2n6c  PUFA  0.000750626 0.000302127
Rho(-)  Phytoplankton   C20.3n6   HUFA  0.000139456 0.000241546
Rho(-)  Phytoplankton   C20.4n6c  HUFA  0.009450224 0.000734239
Rho(-)  Phytoplankton   C20.3n3   HUFA  0.00504895  0.006997548
Rho(-)  Phytoplankton   C22.0     SFA   0           0
Rho(-)  Phytoplankton   C20.5n3c  HUFA  0.120287457 0.01227192
Rho(-)  Phytoplankton   C22.1n9c  MUFA  0.007986444 0.008414274
Rho(-)  Phytoplankton   C24.0     SFA   0.00121246  0.000926446

我尝试了两种制作情节的方法,

方法1 (分别绘制质量,并使用multiplot())

P.polyp.artem <-
   ggplot(polyp.artem2SE, aes(x=component, y=value*100, fill=group))+
   geom_bar(stat="identity", position="identity", colour='grey')+
   geom_errorbar(aes(ymin=(value-se)*100, ymax=(value+se)*100),
            width=0.3)+
   scale_x_discrete(expand = c(0, 0))+
   scale_y_continuous(expand = c(0, 0), limits=c(0,40))+
   scale_fill_brewer(palette="Reds")+
   labs(x='',
        y='',
        title='  Polyp(Art)')+
   mytheme+
   theme(legend.position = 'none',
        axis.text.y = element_blank(),
        axis.text.x = element_blank(),
        plot.margin=unit(c(1,1,0,0), "lines"),
        plot.title = element_text(margin = margin(t = 10, b = -20), size=12),
        panel.border=element_blank())

multiplot(P.polyp.aca1, P.aca1, P.rho1,
          P.polyp.aca2, P.aca2, P.rho2,
          P.polyp.artem,P.artem,
          cols=3)
... ...

情节喜欢,  enter image description here

我对这个图的问题是, 1)如何将x轴文本的图形区域调整为与其他图像相同的尺寸; 2)如何从数字中提取图例并将其放在正确位置?

方法2 (在ggplot2中使用facet_wrap()绘图)

ggplot(data=foodquality.fa, aes(x=component, y=value*100, fill=group))+
  geom_bar(stat = "identity",position = position_dodge()) + 
  geom_errorbar(aes(ymin=(value-se)*100, ymax=(value+se)*100),
                position = position_dodge(), width=0.3)+

  scale_y_continuous(expand = c(0, 0), limits=c(0,40))+

  facet_wrap(organism~quality) +
  scale_fill_brewer(palette="Greens")+

  labs(x='',
       y='% Total FA'
       )+

  geom_hline(yintercept=0)+
  geom_vline(xintercept=0)+

  mytheme+
  theme(legend.position = c(0.7,0.15),
        axis.text.x = element_text(angle = 60, hjust=1, size=10),
        panel.border=element_blank(),
        strip.text=element_blank(),
        strip.background=element_rect(colour="white", 
                                      fill="white"),
        axis.line = element_line(colour = "black"))

情节如,  enter image description here 对于这个图,我想 1)保持每个面板中的垂直线; ** 2)**如果我可以使用不同的填充颜色做正确的两个面板,那将是完美的。

任何批准这两个数字,我将非常感激!!! 谢谢。

0 个答案:

没有答案