-1

In the attached graphic the dots mean the average value of selectivity of each specie. In this plot, I would like

1) to have larger font sizes of the smaller dots referents to the smaller body mass (bodymass<9Kg). I wanted to reduce the scale of difference between the dots by placing the smaller ones a little larger, but keeping the others biggest (>9Kg) in the same size.

2) I would like too add a black border around the dots (this is just to highlight the points)

3) I would like to add the standard deviation (sd) of each average dot. The mean and standard deviation values are shown respectively in columns "media'' and ''sp''.

Could someone help me? thanks

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

Fran Braga
  • 197
  • 2
  • 14
  • 2
    You've now asked this question thrice. Maybe take some time to find out why it's not generating answers? – NelsonGon Feb 03 '19 at 10:49
  • 1
    I deleted the previous questions and completely reformulated them. So I thought it was better to create a new post than to put this change in the old post – Fran Braga Feb 03 '19 at 10:53
  • 2
    1) not exactly sure which text you want to change - AFAIK axis text cannot have different sizes. 2) add a slightly bigger black dot and overlay your point. 3) use `geom_pointrange`. – Roman Luštrik Feb 03 '19 at 11:15
  • Thanks very much for your answer. And you know the command to increase the font size of the dots? – Fran Braga Feb 03 '19 at 12:17
  • 2
    Hi Fran. I urge you to review the [posting rules](https://stackoverflow.com/help/how-to-ask) here on SO. As @NelsonGon remarked, you've asked the *same* question three times, completely ignored any comments asking you to improve said previous questions, and instead kept reposting as a new question. This is *not* how SO works, and usually leads to you very quickly accruing a lot of downvotes. Keep in mind that if you collect too many downvotes you will loose your privilege to post questions altogether. Deleting questions will not avoid this. So please *please* be more considerate; [...] – Maurits Evers Feb 03 '19 at 12:31
  • [continued] read up on how to post and respond to comments. You're asking for free advice here and ignoring comments plus re-posting the same question is quite rude. – Maurits Evers Feb 03 '19 at 12:33
  • Hi Maurits! It was not my intention to be rude in deleting the old post, I just thought it would be better for the understanding of asking to redo a new one by following the suggestions put in the previous comments, than correcting my text or replying it in the comments. Thank you very much for your explanation, I now understand that it would be better to reissue the previous question than to make a new one with the modifications. – Fran Braga Feb 03 '19 at 13:21

1 Answers1

1

Please note that all of your questions have been addressed in one form or the other here on SO. Therefore this seems like an extended multi-duplicate post, and a thorough SO search would've given you all the answers/deetails you needed.

Specifically:

  1. Changing dot sizes can be achieved using one of scale_size, scale_size_area or scale_radius. I'm not entirely clear on what you're asking in point 1, but a look at these functions and playing around with some of the function's parameters should give you what you want.

    Relevant posts are: defining minimum point size in ggplot2 - geom_point , ggplot2: how to manually adjust scale_area

  2. To have filled dots with a black outline use pch = 21 and then use a fill aesthetic with colour = "black".

    This is a duplicate of: Place a border around points

  3. Horizontal error bars can be achieved with geom_errorbarh; vertical ones (if necessary) if geom_errorbar.

    Relevant posts are: ggplot2 : Adding two errorbars to each point in scatterplot, Remove endpoints from error bars in ggplot2

All up, you'd end up with something like this:

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


Sample data

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)
Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Maurits Thank you very much for your help I searched a lot before submitting the question here, but I was using the wrong terms. The links you wrote were also very useful. Thank you for the help with the script and links again and I'll pay more attention to the SO rules before my next question! – Fran Braga Feb 05 '19 at 23:14
  • Hi @FranBraga; you're very welcome. Please don't be discouraged from posting in the future; sometimes the tone around here can be a bit blunt, just keep in mind that most people here are volunteering their free time answering other people's questions and the easier you make it for others the more positive a response you're going to get. That includes trying to find related/similar questions. The great thing is that often somebody would've already asked something very similar in the past. Good luck with your work! – Maurits Evers Feb 06 '19 at 06:06