小提琴图上带有刻面并填充R

时间:2018-09-27 16:27:38

标签: r ggplot2 boxplot facet-grid violin-plot

我正在尝试用每个小提琴图中的箱形图创建小提琴图。当前,在组合填充分组时,将基于x变量创建箱线图。我希望每个x变量的每个填充组都有一个箱线图。

感谢您的帮助!

ggplot(aes(y = HGT.Diff,
           x = `Platform`,
           fill = Metric,
           color = Metric),
       data = dta_compile) +
  geom_violin(draw_quantiles = c(0.5)) +
  geom_boxplot(width = 0.1, fill = "grey", color = "black") +
  ylim(0,1) +
  labs(title = "Comparing Ground Filters",
       x = "Flight Date", 
       y = "Absolute Difference to Manual HGT Measurmenets (m)") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=.4)) +
  facet_grid(`Flight.Date` ~ `GroundFilter`)

Current Violin Plot of above script

1 个答案:

答案 0 :(得分:1)

通过在小提琴和箱形图上设置闪避设置来获得所需的结果。谢谢您的帮助!

ggplot(aes(y = HGT.Diff,
       x = `Platform`,
       fill = Metric,color=Metric),
       data = dta_compile) +
geom_violin(position=position_dodge(),draw_quantiles=c(0.5)) +
geom_boxplot(width=0.1,color="black",position = position_dodge(width =0.9))+
ylim(0,1) +
labs(title="Comparing Ground Filters",
     x="Flight Date", 
     y="Absolute Difference to Manual HGT Measurmenets (m)") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=.4)) +
facet_grid(`Flight.Date`~`GroundFilter`)

Revised Violin Plot