R语言ggplot2绘图

facet细节

2018-12-19  本文已影响5人  热衷组培的二货潜
ggplot(data, aes(context,number, fill = type)) + 
  geom_rect(data = data,aes(fill = type),xmin = -Inf,xmax = Inf,
            ymin = -Inf,ymax = Inf,alpha = 0.1) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_grid(DMR_length~type,  scales="free_y") + 
  scale_fill_brewer(palette = "Set1") + # palette = "YlGnBu" , "Set1"
  geom_text( aes( label = number, y = number),
             vjust = -0.1, size = 4,  fontface = "bold") +
  theme_bw()+
  theme(panel.grid=element_blank()) +
  theme(legend.key=element_rect(linetype='dashed',color="white"),
        axis.text.y = element_text(size=13),
        axis.text.x = element_text(size=18, face="bold"),
        legend.title = element_text(size=16),
        legend.text = element_text(size=15),
        legend.key.height=unit(1.2,'cm')) +
  theme(axis.text.x = element_text( angle = 45,  hjust = 1 ) ) +
  theme(strip.background = element_rect(size = 1)) +
  # theme(strip.background =element_rect(fill= "grey", size = 1)) +
  theme(strip.text.x = element_text(size=12, color = "black",
                                    face="bold.italic"),
        strip.text.y = element_text(size=12, color = "black",
                                    face="bold.italic")) +
  ylim(0, 15000)
image.png
ggplot(data, aes(context,number, fill = type, label = number)) + 
  geom_rect(data = data,aes(fill = type),xmin = -Inf,xmax = Inf,
            ymin = -Inf,ymax = Inf,alpha = 0.1) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_grid(DMR_length~type,  scales="free_y") + 
  scale_fill_brewer(palette = "Set1") + # palette = "YlGnBu" , "Set1"
  theme_bw()+
  theme(panel.grid=element_blank()) +
  theme(legend.key=element_rect(linetype='dashed',color="white"),
        axis.text.y = element_text(size=13),
        axis.text.x = element_text(size=18, face="bold"),
        legend.title = element_text(size=16),
        legend.text = element_text(size=15, face="bold"),
        legend.key.height=unit(1.2,'cm')) +
  theme(axis.text.x = element_text( angle = 45,  hjust = 1 ) ) +
  theme(strip.background = element_rect(size = 1)) +
  # theme(strip.background =element_rect(fill= "grey", size = 1)) +
  theme(strip.text.x = element_text(size = 12, color = "black",
                                    face = "bold.italic"),
        strip.text.y = element_text(size = 12, color = "black",
                                    face = "bold.italic")) +
  ylim(0, 15000) +
  geom_label(aes(fill = factor(type)), colour = "white", fontface = "bold")
image.png
上一篇下一篇

猜你喜欢

热点阅读