0

I have the following R code to plot the counts for two values side by side each month (d1 and d2). Before summarising with ddply, I have the count for separate 'posts' made on different dates.

I really want / need to add a space between the paired bars each month, and labels for each month, so it is clearer to read. Can anybody suggest what I should do for this?

m_scores = ddply(data_NKsam2,.(zdate),summarise, d1 = sum(d1) , d2 = sum(d2))

require(tidyr)

df <- gather(m_scores, event, total, d1:d2)

plot <- ggplot(df, aes(zdate, total, fill=event))
plot <- plot + geom_bar(stat = "identity", position = 'dodge')

This code currently produces a chart like this:

enter image description here

Here is a section of the data 'm_scores'

  zdate  d1   d2
11 Nov 2014 263  318
12 Dec 2014 430  662
13 Jan 2015 507  326
14 Feb 2015 326  279
15 Mar 2015 281  345
16 Apr 2015 352  260
17 May 2015 280  315
18 Jun 2015 243  238
19 Jul 2015 313  251
20 Aug 2015 446  439
21 Sep 2015 416  404
22 Oct 2015 616  423
23 Nov 2015 269  242
24 Dec 2015 781  527
25 Jan 2016 865  861
26 Feb 2016 997 2139
27 Mar 2016 920 1421
28 Apr 2016 376  498
29 May 2016 434  309
30 Jun 2016 271  284

Nick Olczak
  • 305
  • 3
  • 14
  • 1
    Can you include some (dummy) data that we can use with your plotting code to test around things with? Preferably with the same structure as `df` (same column names, and vector types). – teunbrand Apr 12 '21 at 08:54
  • 1
    Is this what you are after? https://stackoverflow.com/questions/6085238/adding-space-between-bars-in-ggplot2 – O.A Apr 12 '21 at 09:44
  • Thanks. @O.A that looks pretty useful... – Nick Olczak Apr 12 '21 at 13:18
  • Also, thanks for your reply @teunbrand I am going to reproduce the data tomorrow... – Nick Olczak Apr 12 '21 at 13:18
  • The linked answer did not really work, neither did https://stackoverflow.com/questions/51892875/ - as both came back with 'position_dodge requires non-overlapping x intervals'. I added some dummy data, any chance you could help me out with finding solution still. Thanks! – Nick Olczak Apr 17 '21 at 14:18

0 Answers0