专用箱线图:在误差线上画线以突出显示R中的数据范围

时间:2019-02-01 08:55:10

标签: r ggplot2 graphics boxplot

概述

我有一个名为 ANOVA.Dataframe.1(见下文)的数据框,其中包含名为“ Canopy_Index”的因变量自变量 strong>称为“ Urbanisation_index”。

我的目标是为城市化指数的每个类别生成一个箱盒图(与下面的预期结果完全相同) ,画线指向误差线的底部和顶部,以突出显示数据范围。

我已经进行了深入搜索,以找到生成所需箱形图的代码(请查看所需结果),但我没有成功,而且我不确定这些箱形图是否具有专业名称。

也许可以在 ggplot Base R

中实现

如果有人可以提供帮助,我将非常感激。

所需结果Reference

enter image description here

我可以使用下面的R代码生成普通的箱线图,但是我无法弄清楚如何实现指向误差线末端的线。

R代码

Boxplot.obs1.Canopy.Urban<-boxplot(ANOVA.Dataframe.1$Canopy_Index~ANOVA.Dataframe.1$Urbanisation_index,
                               main="Mean Canopy Index (%) for Categories of the Urbansiation Index",
                               xlab="Urbanisation Index",
                               ylab="Canopy Index (%)")

从R代码生成的箱线图

enter image description here

数据框1

structure(list(Urbanisation_index = c(2, 2, 4, 4, 3, 3, 4, 4, 
4, 2, 4, 3, 4, 4, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 
2, 2, 2, 4, 4, 3, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 4, 4, 4, 
4, 4, 4, 4), Canopy_Index = c(65, 75, 55, 85, 85, 85, 95, 85, 
85, 45, 65, 75, 75, 65, 35, 75, 65, 85, 65, 95, 75, 75, 75, 65, 
75, 65, 75, 95, 95, 85, 85, 85, 75, 75, 65, 85, 75, 65, 55, 95, 
95, 95, 95, 45, 55, 35, 55, 65, 95, 95, 45, 65, 45, 55)), row.names = c(NA, 
-54L), class = "data.frame")

数据框2

structure(list(Urbanisation_index = c(2, 2, 4, 4, 3, 3, 4, 4, 
4, 3, 4, 4, 4, 4, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 
2, 2, 2, 4, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 4, 4, 4
), Canopy_Index = c(5, 45, 5, 5, 5, 5, 45, 45, 55, 15, 35, 45, 
5, 5, 5, 5, 5, 5, 35, 15, 15, 25, 25, 5, 5, 5, 5, 5, 5, 15, 25, 
15, 35, 25, 45, 5, 25, 5, 5, 5, 5, 55, 55, 15, 5, 25, 15, 15, 
15, 15)), row.names = c(NA, -50L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

爱丽丝,这是您要找的东西吗?

enter image description here

您可以使用df['C5'] = df.apply(lambda x : 1 if x['A'] == x['B'] else 0, axis=1) print (df) A B C1 C2 C3 C4 C5 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 5 2 1 0 0 0 0 0 6 2 0 0 0 0 0 0 7 2 0 0 0 0 0 0 8 2 0 0 0 0 0 0 9 2 0 0 0 0 0 0 做所有事情,但是对于非标准的事情,您必须使用它一段时间。我的代码:

ggplot2