更改面板图中直方图的顺序

问题描述 投票:0回答:1

我制作了一张面板图,比较了收获区域和非收获区域之间牡蛎壳高度频率的直方图,但一个直方图(较小的)落后于一个面板中较大的直方图,并且有点模糊。我希望有一种方法可以只更改这一个面板(马坦萨斯河)并保持其余部分不变,这样我就不必更改我的配色方案。

这是图片: enter image description here

这是我用来做这个的代码:

  ggplot(aes(x=Shell, fill=Harvest, color = Harvest)) +
  geom_histogram(alpha=0.5, position = 'identity') + 
  scale_fill_manual(values = harvest_colors) + 
  scale_color_manual(values = harvest_colors) +
  labs(x = "Shell Height (mm)", y = "Frequency") + facet_wrap(~Region) +
  theme(panel.background = element_blank(), axis.line=element_line(size=1), 
        plot.title = element_text(hjust = 0.5)) +
  geom_vline(xintercept = 75, linetype = "dashed") + 
  ggtitle("Oyster Measurement Frequency by Region")

harvest_colors = c("Yes" = 'black', "No" = 'gray49')
  

数据可以在我的github上找到:https://github.com/hprev30/oysterharvest标题为“Sh.csv”

r ggplot2
1个回答
0
投票

如果重叠是一个问题,您可以尝试使用 ggridges 包来比较壳高度的 密度(不是频率):

library(ggridges)

ggplot(data, aes(x=Shell, fill=Harvest, color = Harvest)) +
  geom_density_ridges(aes(y=Harvest)) + 
#  geom_histogram(alpha=0.5, position = 'identity') + 
  scale_fill_manual(values = harvest_colors) + 
  scale_color_manual(values = harvest_colors) +
  labs(x = "Shell Height (mm)", y = "Density") + 
  facet_wrap(~Region) +
  theme(axis.text.y=element_blank(),
        panel.background = element_blank(), 
        axis.line=element_line(size=1), 
        plot.title = element_text(hjust = 0.5)) +
  geom_vline(xintercept = 75, linetype = "dashed") + 
  ggtitle("Oyster Measurement Frequency by Region")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.