0

I'm plotting a monthly time series of abundance using a bar chart, and there are some months where I don't have data to show. It is possible to add blank spaces y the categorical x-axis?

This is my data:

library(dplyr)
library(ggplot2)

structure(list(spp = structure(c(9L, 10L, 1L, 2L, 3L), .Label = c("sp10", "sp15", "sp16", "sp20", "sp21", "sp22", "sp23", "sp24", "sp8", "sp9"), class = "factor"), abundance = c(0, 0, 0, 0, 11.19404656), estation = c(5L, 5L, 5L,5L, 5L), year = c(1995L, 1995L, 1995L, 1995L, 1995L), month = structure(c(2L, 2L, 2L, 2L, 2L), .Label = c("abr", "dic", "ene", "feb"), class = "factor"), date = structure(c(2L, 2L, 2L, 2L, 2L), .Label = c("abr-96", "dic-95", "ene-96", "feb-96"), class = "factor")), row.names = c(NA, 5L), class = "data.frame")

subset_group <- subset %>% group_by(date,spp) %>% summarize(sum_pl = sum(abundance))

ggplot(subset_group, aes(x = date, y = sum_pl, fill = spp)) + geom_bar(stat = "identity") + scale_x_discrete(labels = c("dic-95" = "D", "ene-96" = "E", "feb-96" = "F", "M", "abr-96" = "A"))

I used scale_x_discrete(), but with no positive results.

  • 2
    I'd suggest actual dates and `scale_x_date`, then your spacing will be correct, and you can specify to show every month regardless of data. – Gregor Thomas Oct 25 '19 at 16:10
  • Keep in mind that we don't have any of your data, so we can't run your code, and we can't see any output, so right now the best anybody can do is guess as to what's going on and how you might fix it. We also don't know what "no positive results" means. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on writing an R question that folks can more easily help with. – camille Oct 25 '19 at 16:49

0 Answers0