I'm creating a bubble plot of species abundance across several areas/times. I need the Y axis to be in species taxonomic order from the top, so have a separate integer column "Number" which I am using to create the plot to retain the right order. But I then have to replace the Y axis labels with the "Species" column.
I'm probably overlooking something simple but I've tried several things and cannot get anything to work.
The reason I cannot make the plot using the species column is that there are more than 100 species in total, and R turns the order to alphanumeric which is even worse. I tried fixing it that way as well.
I've tried conserving the order when importing, the scale_y_discrete
function (see below) and several other solutions proposed elsewhere. Str_order is no longer available as well as one or two other recommended commands that I've come across.
Any advice would be very welcome.
ggplot(data, aes(x=Sample, y=Number)) +
geom_point(aes(size=ifelse(Value==0, NA, Value), alpha = 0.75)) +
scale_size(range = c(0, 5)) +
scale_y_discrete(limits=c(data$Species)
structure(list(Year = c("1984 - 1989", "2017 - 2020", "1984 - 1989",
"2017 - 2020", "1984 - 1989", "2017 - 2020", "1984 - 1989", "2017 - 2020",
"1984 - 1989", "2017 - 2020", "1984 - 1989", "2017 - 2020", "1984 - 1989",
"2017 - 2020", "1984 - 1989", "2017 - 2020", "1984 - 1989", "2017 - 2020",
"1984 - 1989", "2017 - 2020", "1984 - 1989", "2017 - 2020", "1984 - 1989",
"2017 - 2020", "1984 - 1989", "2017 - 2020", "1984 - 1989", "2017 - 2020",
"1984 - 1989", "2017 - 2020"), Sample = c("Developed_zone_1992",
"Developed_zone_2020", "Paddock_zone_1992", "Paddock_zone_2020",
"Sanctuary_zone_1992", "Sanctuary_zone_2020", "Developed_zone_1992",
"Developed_zone_2020", "Paddock_zone_1992", "Paddock_zone_2020",
"Sanctuary_zone_1992", "Sanctuary_zone_2020", "Developed_zone_1992",
"Developed_zone_2020", "Paddock_zone_1992", "Paddock_zone_2020",
"Sanctuary_zone_1992", "Sanctuary_zone_2020", "Developed_zone_1992",
"Developed_zone_2020", "Paddock_zone_1992", "Paddock_zone_2020",
"Sanctuary_zone_1992", "Sanctuary_zone_2020", "Developed_zone_1992",
"Developed_zone_2020", "Paddock_zone_1992", "Paddock_zone_2020",
"Sanctuary_zone_1992", "Sanctuary_zone_2020"), Colour = c(1L,
1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L,
3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L), Value = c(2L,
5L, 10L, 10L, 0L, 10L, 2L, 0L, 0L, 5L, 0L, 10L, 0L, 0L, 5L, 10L,
0L, 5L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 1L, 0L, 10L, 0L, 10L), Family = c("Phasianidae",
"Phasianidae", "Phasianidae", "Phasianidae", "Phasianidae", "Phasianidae",
"Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae",
"Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae",
"Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae",
"Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae", "Anatidae"
), Species = c("1. Grey francolin (60)", "1. Grey francolin (60)",
"1. Grey francolin (60)", "1. Grey francolin (60)", "1. Grey francolin (60)",
"1. Grey francolin (60)", "2. Egyptian goose (55)", "2. Egyptian goose (55)",
"2. Egyptian goose (55)", "2. Egyptian goose (55)", "2. Egyptian goose (55)",
"2. Egyptian goose (55)", "3. Garganey (60)", "3. Garganey (60)",
"3. Garganey (60)", "3. Garganey (60)", "3. Garganey (60)", "3. Garganey (60)",
"4. Northern shoveler (62)", "4. Northern shoveler (62)", "4. Northern shoveler (62)",
"4. Northern shoveler (62)", "4. Northern shoveler (62)", "4. Northern shoveler (62)",
"5. Mallard (67)", "5. Mallard (67)", "5. Mallard (67)", "5. Mallard (67)",
"5. Mallard (67)", "5. Mallard (67)"), Number = c(142L, 142L,
142L, 142L, 142L, 142L, 141L, 141L, 141L, 141L, 141L, 141L, 140L,
140L, 140L, 140L, 140L, 140L, 139L, 139L, 139L, 139L, 139L, 139L,
138L, 138L, 138L, 138L, 138L, 138L)), class = "data.frame", row.names = c(NA,
-30L))
Thanks in advance.