“散点图”相对与标准偏差的平均值

问题描述 投票:-1回答:1

在所附的图形的点的意思是每一个物种的选择性的平均值。在这个情节,我想

1)有较小的点对象,到较小的体重(体质量<9公斤)的更大的字体尺寸。我想通过将较小的大一点,但保持了别人最大的(>9千克)在相同的尺寸,以减少点之间差异的规模。

2)我想得加点周围的黑色边框(这只是突出点)

3)我想添加的每个点的平均的标准偏差(SD)。的平均值和标准偏差值在列“媒介‘分别示出’和‘’SP‘’。

可能有人帮助我吗?谢谢

library(tidyverse)
Dataset %>%
ggplot(aes(x = media, y = specie, 
             colour = energetic_level, size = log(bodymass))) +
  geom_point(alpha = .9) +
  scale_colour_continuous(low = 'green', high = 'red') +
  labs(x = 'Response rate', y = 'Species') +
  ggthemes::theme_few() +
  theme(axis.text.x = element_text(angle = 90, vjust = .5)) 
media   dp  specie  bodymass    energetic_level
4.063478961 3.627269468 AAChlor_cyn 5000.01 3.2
4.05537378  3.585436083 ABOtol_cras 1206.61 2.4
3.999309751 3.818689333 ACMiop_tal  1248.86 3
3.945049659 3.855743536 BACerc_mit  5041.29 2.5
3.862515658 3.687924328 BCThry_swin 4000    2.8
3.655056928 3.732785731 DAHys_afri  14936.02    2.8
3.56041853  3.478167947 DBLep_cap   1500    3
3.402431689 3.446995588 DCCivet_civ 12075.58    4.6
3.401743858 3.569716116 FGenet_gen  1756.17 6.1
3.39029097  3.414370313 GALept_serv 11999.96    7
3.39009097  1.552336764 GBPhil_mont 4896.05 2.6
3.32029097  1.920646552 HOryct_afer 56175.2 5
3.239734182 3.540636613 IHipp_amph  1536310.4   3
3.154474564 3.526089786 JBSylv_grim 15639.15    3.2
2.883544415 3.007873613 MAPota_larv 69063.79    3.3
2.719993477 1.308813082 MBTrag_scri 43250.39    3
2.718552867 3.080761281 MCPant_pa   52399.99    7
1.982822501 2.085016316 MDRed_aru   58059.24    3
1.529854402 1.814623348 MFSync_caf  592665.98   3
1.443776834 1.254052861 NLox_afric  3824539.93  3
1.402107786 1.637998721 OCan_mes    22000   5.2
1.164299734 1.397597868 PPant_le    158623.93   6.8
0.887732043 1.318886523 QLyc_pict   21999.99    7
0.82952687  0.789227213 UCroc_croc  63369.98    7
0.782973623 0.570878282 VTrag_oryx  562592.69   2.7
0.477482615 0.624782141 YHipp_eq    264173.96   3

enter image description here

r ggplot2 tidyverse standard-deviation
1个回答
1
投票

请注意,您的所有问题都以某种形式或其他在这里SO得到解决。因此,这似乎是一个延伸的多重复的帖子,彻底SO搜索将已经给你所有你所需要的答案/ deetails。

特别:

  1. 改变点尺寸可以使用scale_sizescale_size_areascale_radius之一来实现。我不是你问1点什么完全清楚,但看看这些功能和玩弄一些函数的参数应该给你你想要的东西。 相关职位:defining minimum point size in ggplot2 - geom_point ggplot2: how to manually adjust scale_area
  2. 要与黑色轮廓使用pch = 21实心点,然后使用fill审美与colour = "black"。 这是一个重复:Place a border around points
  3. 水平误差线可以用geom_errorbarh实现;垂直酮(如果必要的话),如果geom_errorbar。 相关职位:ggplot2 : Adding two errorbars to each point in scatterplotRemove endpoints from error bars in ggplot2

所有的,你想最终是这样的:

library(ggthemes)
library(ggplot2)
ggplot(df, aes(media, specie, fill = energetic_level)) +
    geom_errorbarh(aes(xmax = media + dp, xmin = media - dp)) +
    geom_point(aes(size = log(bodymass)), pch = 21, colour = "black", alpha = .9) +
    scale_fill_continuous(low = 'green', high = 'red') +
    scale_size_area() + 
    labs(x = 'Response rate', y = 'Species') +
    ggthemes::theme_few() +
    theme(axis.text.x = element_text(angle = 90, vjust = .5))

enter image description here


样本数据

df <- read.table(text =
    "media   dp  specie  bodymass    energetic_level
4.063478961 3.627269468 AAChlor_cyn 5000.01 3.2
4.05537378  3.585436083 ABOtol_cras 1206.61 2.4
3.999309751 3.818689333 ACMiop_tal  1248.86 3
3.945049659 3.855743536 BACerc_mit  5041.29 2.5
3.862515658 3.687924328 BCThry_swin 4000    2.8
3.655056928 3.732785731 DAHys_afri  14936.02    2.8
3.56041853  3.478167947 DBLep_cap   1500    3
3.402431689 3.446995588 DCCivet_civ 12075.58    4.6
3.401743858 3.569716116 FGenet_gen  1756.17 6.1
3.39029097  3.414370313 GALept_serv 11999.96    7
3.39009097  1.552336764 GBPhil_mont 4896.05 2.6
3.32029097  1.920646552 HOryct_afer 56175.2 5
3.239734182 3.540636613 IHipp_amph  1536310.4   3
3.154474564 3.526089786 JBSylv_grim 15639.15    3.2
2.883544415 3.007873613 MAPota_larv 69063.79    3.3
2.719993477 1.308813082 MBTrag_scri 43250.39    3
2.718552867 3.080761281 MCPant_pa   52399.99    7
1.982822501 2.085016316 MDRed_aru   58059.24    3
1.529854402 1.814623348 MFSync_caf  592665.98   3
1.443776834 1.254052861 NLox_afric  3824539.93  3
1.402107786 1.637998721 OCan_mes    22000   5.2
1.164299734 1.397597868 PPant_le    158623.93   6.8
0.887732043 1.318886523 QLyc_pict   21999.99    7
0.82952687  0.789227213 UCroc_croc  63369.98    7
0.782973623 0.570878282 VTrag_oryx  562592.69   2.7
0.477482615 0.624782141 YHipp_eq    264173.96   3", header = T)
© www.soinside.com 2019 - 2024. All rights reserved.