如何在ggplot2的boxplot上显示观测的名称?

假设您有一个包含公司名称,效率指标及其值的数据框。我想通过指标可视化值的分布。此外,我想在方框图中显示公司名称。

我成功制作了箱线图。但是,我也尝试使用geom_text(label = ...)显示公司名称。在我只想显示特定公司的名称之前,也可以。

问题:如何在箱形图中仅描绘一个公司名称?

样本数据:

structure(list(comp_name = c("Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", "Andrew", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter", "Peter", "Peter", "Peter", 
"Peter", "Peter", "Peter", "Peter"), indicator = c("F1", "F1", 
"F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", 
"F1", "F1", "F1", "F1", "F1", "F1", "F1", "F2", "F2", "F2", "F2", 
"F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", 
"F2", "F2", "F2", "F2", "F2", "F3", "F3", "F3", "F3", "F3", "F3", 
"F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", 
"F3", "F3", "F3", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", 
"F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", "F1", 
"F1", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", 
"F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F3", 
"F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3", 
"F3", "F3", "F3", "F3", "F3", "F3", "F3", "F3"), value = c(4.52116335801444, 
6.98749208273682, 4.06677492882586, 5.15558916506456, 2.55021540348946, 
4.03979028008168, 3.751515686978, 5.08003125851194, 8.7555968159682, 
5.4394771555829, 1.19766306732289, 5.93147731602626, 5.59646604833006, 
1.73138645071719, 5.11918222532415, 5.83342701888127, 4.3063821275868, 
5.46551649254734, 2.03791096436598, 6.78824196220435, 7.06567057699402, 
2.12718564271759, 2.2767564436691, 2.9340306023389, 2.79354137930189, 
1.74012197713116, 4.63834192235623, 4.92206445766098, 5.92405081403378, 
8.09782132090054, 6.97285432280469, 5.07130341848169, 3.30182914153493, 
3.34397253870246, 3.46478566548551, 2.3993549803844, 2.57123338842713, 
5.3477268015452, 4.91017847933986, 3.06690395074572, 4.88326550588307, 
6.14840924478227, 3.03774145148148, 2.15503416860755, 2.59633674164204, 
4.42310726849601, 2.13363689471252, 0.456381227308591, 5.691163348962, 
0.912347547789089, 5.77435176159163, 4.07402763667729, 3.82057336446912, 
3.34397163555984, 3.29222606327468, 6.16552682906508, 4.35344041700362, 
7.67032346030189, 3.26348961010125, 5.25322571330987, 3.66694544697633, 
6.0361925048948, 2.88873148939352, 8.45661226220137, 7.87329217470112, 
2.70345782748427, 6.91511647510829, 1.54134508545522, 2.18208998284389, 
3.16124793548385, 4.31666612130624, 4.54958484376762, 8.50892596634577, 
7.5225632222216, 4.58217957515625, 4.08628383752229, 6.77539922377002, 
7.78460326932369, 6.25295512473375, 5.48269676141167, 3.84114520608033, 
2.41963345063092, 2.912374298312, 7.17268035511083, 3.81530974737139, 
1.80282982429818, 3.50746999074847, 5.15224746117473, 5.18355688999888, 
5.47519426645026, 9.87303057407119, 6.07147247898117, 3.19602380164489, 
2.59514592800692, 7.35458770398942, 5.4947663156565, 5.90316497585236, 
5.68887350708009, 0.992336549260927, 5.40819995742745, 2.75688036687868, 
5.30089244576671, 0.623445829887006, 5.10340466234114, 3.73065932502235, 
3.75666881288993, 1.7474419966562, 4.32062928836251, 6.72395389095317, 
1.69971729442571, 6.77489190923027, 5.34359382756765, 2.65431117498653, 
2.33790746229386, 3.4362010025597, 4.67710789802222, 4.7103208700674, 
5.78846064996488, 7.23020019917477, 4.07601609654997)), class = "data.frame", row.names = c(NA, 
-120L))

我试图做的是:

ggplot(sampleData, aes(x = indicator, y = value)) +
  geom_boxplot() + geom_text(label = comp_name)

好吧,答案在表面上。

在这里找到:https : //www.r-graph-gallery.com/275-add-text-labels-with-ggplot2.html

如果要放置一个或多个标签,请根据需要使用geom_textgeom_label过滤数据框。像这样

    ggplot(data, aes(x = factor, y = value)) + 
       geom_boxplot() + 
       geom_label(data = data %>% filter(indicator == "f1"), aes(label = indicator))

您甚至可以制作自定义标签。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在x轴上添加代表ggplot2中所有观测值的因子水平?

来自分类Dev

如何在ggplot2的x轴上使用月份的名称

来自分类Dev

GGPlot2 Boxplot仅显示平线

来自分类Dev

如何在ggplot2中显示obs的方向(标题)

来自分类Dev

如何在ggplot2的图例中显示缺失值?

来自分类Dev

在ggplot2 boxplot上添加多个标签

来自分类Dev

在ggplot2中将鼠标悬停时如何在工具提示上显示y值

来自分类Dev

如何使用ggproto扩展ggplot2 boxplot?

来自分类Dev

计数表中的ggplot2 boxplot

来自分类Dev

在ggplot2中重新排序Boxplot

来自分类Dev

ggplot2中的Boxplot给垃圾

来自分类Dev

R ggplot2 - 如何在相同的 x 值上绘制 2 个箱线图

来自分类Dev

如何在ggplot2中以数字矢量的降序显示条形?

来自分类Dev

如何在ggplot2中自动突出显示x轴的多个部分?

来自分类Dev

如何在ggplot2中按组显示摘要统计信息

来自分类Dev

如何在地图ggplot2上高亮显示/绘制一条纬线

来自分类Dev

如何在ggplot2中将geom_text显示为百万

来自分类Dev

如何在SQL上显示表的名称

来自分类Dev

使用ggplot2行在boxplot上连接数据点

来自分类Dev

如何在R中的ggplot2中的图块上放置标签?

来自分类Dev

如何在ggplot2中的geom_rect对象上应用渐变填充?

来自分类Dev

R:ggplot2,如何在面板图的每个面板上注释摘要统计信息

来自分类Dev

ggplot2:如何在分组的barplot上添加线和p值?

来自分类Dev

如何在GGplot2中的条上添加百分号

来自分类Dev

如何在R中的ggplot2中的图块上放置标签?

来自分类Dev

如何在ggplot2中的alpha值上使用任意向量

来自分类Dev

如何在R中的OSM切片上叠加点密度(ggplot2)?

来自分类Dev

如何在堆积的条形图ggplot2上组织百分比值

来自分类Dev

ggplot2上的Stat_smooth未显示

Related 相关文章

  1. 1

    如何在x轴上添加代表ggplot2中所有观测值的因子水平?

  2. 2

    如何在ggplot2的x轴上使用月份的名称

  3. 3

    GGPlot2 Boxplot仅显示平线

  4. 4

    如何在ggplot2中显示obs的方向(标题)

  5. 5

    如何在ggplot2的图例中显示缺失值?

  6. 6

    在ggplot2 boxplot上添加多个标签

  7. 7

    在ggplot2中将鼠标悬停时如何在工具提示上显示y值

  8. 8

    如何使用ggproto扩展ggplot2 boxplot?

  9. 9

    计数表中的ggplot2 boxplot

  10. 10

    在ggplot2中重新排序Boxplot

  11. 11

    ggplot2中的Boxplot给垃圾

  12. 12

    R ggplot2 - 如何在相同的 x 值上绘制 2 个箱线图

  13. 13

    如何在ggplot2中以数字矢量的降序显示条形?

  14. 14

    如何在ggplot2中自动突出显示x轴的多个部分?

  15. 15

    如何在ggplot2中按组显示摘要统计信息

  16. 16

    如何在地图ggplot2上高亮显示/绘制一条纬线

  17. 17

    如何在ggplot2中将geom_text显示为百万

  18. 18

    如何在SQL上显示表的名称

  19. 19

    使用ggplot2行在boxplot上连接数据点

  20. 20

    如何在R中的ggplot2中的图块上放置标签?

  21. 21

    如何在ggplot2中的geom_rect对象上应用渐变填充?

  22. 22

    R:ggplot2,如何在面板图的每个面板上注释摘要统计信息

  23. 23

    ggplot2:如何在分组的barplot上添加线和p值?

  24. 24

    如何在GGplot2中的条上添加百分号

  25. 25

    如何在R中的ggplot2中的图块上放置标签?

  26. 26

    如何在ggplot2中的alpha值上使用任意向量

  27. 27

    如何在R中的OSM切片上叠加点密度(ggplot2)?

  28. 28

    如何在堆积的条形图ggplot2上组织百分比值

  29. 29

    ggplot2上的Stat_smooth未显示

热门标签

归档