我试图将我的数据表示为箱线图,我的数据框目前如下所示:
V1 V2 V3 V4 V5
1 1 12.18 FEMALE A_ambiguus Host
2 2 11.81 FEMALE A_ambiguus Host
3 3 10.70 MALE A_ambiguus Host
4 4 11.07 MALE A_ambiguus Host
5 5 7.95 FEMALE A_ameliae Parasite
6 6 7.42 FEMALE A_ameliae Parasite
我运行以下脚本并生成一个图形,其中物种 (V4) 作为 x 轴,总长度 (V2) 作为 y 轴,按 V2 排序,按 V5 着色。
box <- ggplot(TL_sub, aes(x = V4, y = V2, group = V4)) +
scale_y_continuous(name = "TL (mm)") +
theme(axis.text.x=element_text(angle = 45, hjust = 1)) +
geom_boxplot(aes(fill=Condition)) +
aes(x=reorder(V4,V2),y=V2,label=TL)
box
问题是当我然后运行
box + facet_grid(. ~ V5)
目标是创建两个按性别分隔的图(V3),但它不起作用。我收到以下错误:
Error in combine_vars(data, params$plot_env, cols, drop = params$drop) :
At least one layer must contain all variables used for facetting
如果需要,我可以提供完整的数据集。
任何帮助都会很棒!谢谢,史蒂文·M。