plot in r with count on y and dates on x axis
0
0
Entering edit mode
2.2 years ago

I'm trying to plot the seasonality of nesting and hatching for turtles on one graph - with the count of how many nests were laid/hatched for every day of the season (01/05/2021-30/09/2021). Some of my data is as follows:

Date - Laid Green - Hatched Green

14/05/2021 - 0 - 0

15/05/2021- 0 - 0

16/05/2021- 0 - 0

17/05/2021- 0 - 0

18/05/2021- 0 - 0

19/05/2021 - 0 - 0

20/05/2021 -1 - 0

21/05/2021- 2 - 0

22/05/2021- 0 - 0

23/05/2021- 1 - 0

24/05/2021 - 2- 0

25/05/2021- 0 - 0

26/05/2021 -1 - 0

27/05/2021 - 4 - 0

The code I'm using is:

ggplot(seasonality,aes(x=Date,y=seasonality$Laid Green))+geom_bar(stat="identity",width=1)

However, it presents each day as one where I would like to pool it to be more visually pleasing. I have attached the current graph for reference. I am also trying to plot the green hatched on the same graph with nesting and hatching in 2 different colours.

Any help is appreciated!enter image description here

r • 1.5k views
ADD COMMENT
0
Entering edit mode

What do you mean pooling? Pool the counts across all the days, and do a barplot like this example?

# Generate example data
seasonality = data.frame(`Date` = seq(as.Date("2021/05/14"), by = "day", length.out = 100),
                         `Laid Green` = rbinom(100, size = 5, prob = 0.75),
                         `Hatched Green` = rbinom(100, size = 10, prob = 0.15),
                         stringsAsFactors = F)
seasonality2 <- reshape2::melt(seasonality[,-1])
ggplot(seasonality2, aes(y = value, x = variable, fill = variable)) + geom_bar(stat = "identity")

Or do you want a plot like this:

seasonality3 <- reshape2::melt(seasonality, id.vars = "Date")
ggplot(seasonality3, aes(x = Date, y = value, fill = variable)) + geom_density(stat = "identity",alpha = 0.5)
ADD REPLY
0
Entering edit mode

Do not delete post that have received feedback. Reply to the people that have given you feedback, and let them know if it was helpful or not. If your problem has been resolved, add an answer stating how it was resolved.

ADD REPLY

Login before adding your answer.

Traffic: 2104 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6