小编oli*_*oli的帖子

ggplot2:boxplot,颜色和文本标签映射到两个分类变量的组合

我想从数据集创建一个带有ggplot2的箱线图,该数据集densityAGRLKA在x轴上有3个分类变量(物种,位置,位置).

以下功能:

ggplot(densityAGRLKA, aes(species, density, fill=location, alpha=position), dodge=species, position) + 
stat_boxplot(geom ='errorbar') + 
geom_boxplot() 
Run Code Online (Sandbox Code Playgroud)

创造了一个情节,其中物种的分组很好,但颜色是误导.我不知道如何解决这个问题.

我需要一个具有以下属性的图:

  • 数据按分组 species
  • 在集团内location,
  • 并在顺序的位置内top,然后bottom.

另外,如果location将它们写在属于一起的两个盒子position下面,并且在每个盒子下面,那就太棒了.或者更好的着色/阴影框然后提供一个清晰的传奇?

样本数据:

densityAGRLKA = structure(list(location = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L), .Label = …
Run Code Online (Sandbox Code Playgroud)

r legend labels ggplot2 boxplot

6
推荐指数
1
解决办法
1363
查看次数

标签 统计

boxplot ×1

ggplot2 ×1

labels ×1

legend ×1

r ×1