Discrete x in barplot

Hey there,

I'm having problems with my data here. I'm trying to show the total amount of wast per Birdnest. The numbers for the nests comes from my field work. My Problem is that in my barplot on the x axis I have these huge gapse between my numbers. How can I tell R to take each value of my Nestnumber as a discrete value? Here is my code:

library(tidyverse)

a <- c(1, 2  , 4,  13,  14,  16  ,17,  18,  20,  24,  25,  29  ,34,  35,  36,  41,    42,  44,  46,  47,  54,  59,  67,  68,  72,  79,  93, 104, 111, 113, 114, 116,119, 122, 124, 125, 129, 176)
b <- c(76, 129,   3,  44  , 5 , 64,  14, 191,  25,  37,  44,   0  ,12,  13  , 8 , 11,11,   2,  12,   2  ,23,   5,  19,  29  ,38 , 17  , 7 ,  2,   0 ,  4   ,3   ,1,0  , 2 , 15  , 5 , 38  , 3)


Nests <- tibble(Nestnumber = a, Amount_waste = b)

nestplot <- ggplot(Nests, aes(x = Nestnumber, y = Amount_waste))+
  geom_bar(stat = 'identity')
  
  nestplot

Created on 2019-11-06 by the reprex package (v0.3.0)

Change Nestnumber into a factor to treat the numbers discretely:

nestplot <- ggplot(Nests, aes(x = factor(Nestnumber), y = Amount_waste))+
  geom_bar(stat = 'identity')
1 Like

Thanks for your fast reply. Solved it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.