Hi community, Im try to put a second y axis with sec.axis()
but get an error. How fix this?
FB_2 <- data.frame(
structure(list(Especie = c("Dasyprocta punctata", "Leopardus pardalis",
"Tamandua mexicana", "Dasypus novemcinctus", "Didelphis marsupialis",
"Cerdocyon thous", "Procyon cancrivorus", "Eira barbara", "Sciurus granatensis",
"Cuniculus paca", "Conepatus semistriatus", "Mazama sanctaemartae",
"Sylvilagus sp", "Herpailurus yagouaroundi", "Dicotyles tajacu",
"Cabassous centralis", "Puma concolor", "Leopardus wiedii", "Metachiurus myosuros",
"Odocoileus cariacou"), Records = c(278L, 237L, 235L, 228L, 226L,
224L, 204L, 191L, 164L, 160L, 143L, 132L, 117L, 90L, 79L, 56L,
40L, 36L, 19L, 17L), Biomass = c(743644.44, 2820318.96, 989345.3,
958461.84, 246602.16, 1173755.52, 1417783.68, 746815.73, 52224.16,
1307608, 288860, 2508000, 137216.43, 618750, 1680068.51, 213357.76,
2064001.6, 116998.92, 6697.5, 943645.52), IUCN.status = c("LC",
"LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "NE",
"NE", "LC", "LC", "DD", "LC", "NT", "NE", "LC")), row.names = c(1L,
6L, 4L, 3L, 2L, 5L, 7L, 8L, 10L, 9L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L), class = "data.frame"))
FB_2 |> ggplot(aes(x=fct_reorder(Especie,-Records) ,y=Records)) +
geom_col() +
coord_flip() +
scale_y_continuous(breaks = seq(0, max(FB_2$Records), 50),
sec.axis = sec_axis( trans=FB_2$Biomass,
name="Second Axis")) + # if remove sec.axis the script run.
annotate(
"text",
x = FB_2$Especie,
y = FB_2$Records,
label = FB_2$IUCN.status,
vjust = 0.5,
hjust = -0.2,
size = 3,
color = "red"
) +
theme(axis.text.x = element_text(vjust = 0.5, hjust = 1, size =10)) +
labs(title = 'Titulo',
x='',
y='No. Records')
#Error in `sec_axis()`:
#! Can't convert `transform`, a double vector, to a function.
Created on 2024-01-29 with reprex v2.0.2