2

I would like

  1. to assign the category of "energetic level" COLORS in the red shades to the higher levels and in green shades to the lower ones.
  2. to order the SIZE of each point of the category "functional level"in the following order low_TL, inter_TL, Myrmecophage, mesocarnivores, large_species, apex carnivores, megafauna (assign to "low_TL" the smaller points size and to megafauna the biggest).

Dataset<-read.csv(file= "meat.csv", header= TRUE, sep= ";" )
library(ggplot2)
options(scipen=999)
theme_set(theme_bw())
gg <- ggplot(Dataset, aes(x=specie, y=responserate))+ 
  geom_point(aes(col=energetic_level, size=functional_level)) + 
  geom_smooth(method="loess", se=F) + 
  labs(subtitle="Bushmeat trade", 
       y="Response rate", 
       x="Body mass")
gg+scale_color_gradient(low="green", high="red", space ="Lab" )
plot(gg)
specie responserate energetic_level functional_level
AAOtol_cras 7.2 2.4 low_TL
ABMiop_tal 1.6 3 low_TL
ACCLep_cap 14.4 3 low_TL
BAThry_swin 20 2.8 low_TL
BBPhil_mont 20.8 2.6 low_TL
BCChlor_cyn 72.8 3.2 low_TL
BDCerc_mit 5.6 2.5 low_TL
CCHys_afri 23.2 2.8 low_TL
FCan_mes 1.6 4.9 inter_TL
PTrag_oryx 16 2.7 low_TL
CBCivet_civ 43.2 4.4 inter_TL
DSylv_grim 48 3.1 inter_TL
IOryct_afer 11.2 5 Myrmecophage
ADGenet_gen 0 5.8 mesocarnivores 
CALept_serv 0.8 5.8 mesocarnivores 
ELyc_pict 0.8 5.8 mesocarnivores 
GTrag_scri 100 3  large_species 
JRed_aru 100 3 large_species 
MPota_larv 100 3.2 large_species 
OHipp_eq 14.4 3 large_species 
QSync_caf 81.6 3  large_species 
HPant_pa 18.4 6 apex carnivores 
LCroc_croc 0 6 apex carnivores 
NPant_le 0 6 apex carnivores 
RHipp_amph 22.4 3 megafauna
SLox_afric 1.6 3 megafauna
The following figure is that I would like to change the point colors and name

enter image description here

utubun
  • 4,400
  • 1
  • 14
  • 17
Fran Braga
  • 197
  • 2
  • 14
  • 1
    Hello, you should be able to change the order of "functional level" by reordering the levels of the factor in the data.frame (like in here: https://rstudio-pubs-static.s3.amazonaws.com/7433_4537ea5073dc4162950abb715f513469.html). I think the scale_color_gradient should work, but you might have forgotten to assigne it to gg before plotting it? – TinglTanglBob Jan 31 '19 at 15:10

1 Answers1

5

You mean something like that?

library(tidyverse)

dat %>%
  mutate(
    functional_level = fct_relevel(functional_level, 
                                   c("low_TL", "inter_TL", "Myrmecophage", 
                                     "mesocarnivores",    "large_species", 
                                     "apex_carnivores",   "megafauna"
                                     )
                                   )
    ) %>%
  ggplot(aes(x = specie, y = responserate, 
             colour = energetic_level, size = functional_level)) +
  geom_point(alpha = .9) +
  scale_colour_continuous(low = '#32CD32', high = '#ff4040') +
  labs(x = 'Species', y = 'Response rate') +
  ggthemes::theme_few() +
  theme(axis.text.x = element_text(angle = 90, vjust = .5))

enter image description here

So the only thing you have to do is relevel your functional_level and after that you can map it into the points size (ggplot will warn you thought) and map energetic_level into point's colour.

Data:

structure(list(specie = structure(c(1L, 2L, 3L, 5L, 6L, 7L, 8L, 
11L, 14L, 23L, 10L, 12L, 17L, 4L, 9L, 13L, 15L, 18L, 20L, 22L, 
24L, 16L, 19L, 21L, 25L, 26L), .Label = c("AAOtol_cras", "ABMiop_tal", 
"ACCLep_cap", "ADGenet_gen", "BAThry_swin", "BBPhil_mont", "BCChlor_cyn", 
"BDCerc_mit", "CALept_serv", "CBCivet_civ", "CCHys_afri", "DSylv_grim", 
"ELyc_pict", "FCan_mes", "GTrag_scri", "HPant_pa", "IOryct_afer", 
"JRed_aru", "LCroc_croc", "MPota_larv", "NPant_le", "OHipp_eq", 
"PTrag_oryx", "QSync_caf", "RHipp_amph", "SLox_afric"), class = "factor"), 
    responserate = c(7.2, 1.6, 14.4, 20, 20.8, 72.8, 5.6, 23.2, 
    1.6, 16, 43.2, 48, 11.2, 0, 0.8, 0.8, 100, 100, 100, 14.4, 
    81.6, 18.4, 0, 0, 22.4, 1.6), energetic_level = c(2.4, 3, 
    3, 2.8, 2.6, 3.2, 2.5, 2.8, 4.9, 2.7, 4.4, 3.1, 5, 5.8, 5.8, 
    5.8, 3, 3, 3.2, 3, 3, 6, 6, 6, 3, 3), functional_level = structure(c(4L, 
    4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 4L, 2L, 2L, 7L, 6L, 6L, 6L, 
    3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 5L, 5L), .Label = c("apex_carnivores", 
    "inter_TL", "large_species", "low_TL", "megafauna", "mesocarnivores", 
    "Myrmecophage"), class = "factor")), class = "data.frame", row.names = c(NA, 
-26L))
utubun
  • 4,400
  • 1
  • 14
  • 17