2016-04-01 17 views
2

私はこれは私がプロットをgenetateするために使用されるコードである9 11 13 15 17 19ggplotのscale_x_dateに変更がありますか?

enter image description here

に8 10 12 14 16 18からのプロットの中断を変更したい:

library(ggplot2) 
df.plot <-structure(list(color = structure(c(2L, 2L, 3L, 1L, 3L, 4L, 3L, 
              1L, 4L, 1L, 2L, 4L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 
              3L, 3L, 3L, 3L), .Label = c("54", "55", "61", "69"), class = "factor"), 
         date = structure(c(16687, 16687, 16687, 16687, 16687, 16687, 
              16688, 16688, 16688, 16689, 16689, 16690, 16693, 16693, 16693, 
              16694, 16694, 16695, 16695, 16695, 16695, 16696, 16696, 16696, 
              16696, 16696, 16696), class = "Date"), facet = c("A", 
                          "A", "A", "A", "A", "B", 
                          "B", "A", "B", "B", "B", "B", 
                          "B", "B", "B", "B", "A", "B", 
                          "A", "B", "A", "C", "B", "C", 
                          "C", "B", "C")), class = "data.frame", row.names = c(NA, 
                                        -27L), .Names = c("color", "date", "facet")) 

ggplot(df.plot, aes(x=date, fill=color)) + 
    geom_dotplot(binwidth=1, stackgroups=TRUE, binpositions="all") + 
    coord_fixed(ratio=1) + 
    ylim(0,7) + 
    scale_x_date(date_labels = "%b %d", date_breaks = "2 day") + 
    theme(
    axis.text.x = element_text(angle = 90, hjust = 1) 
)+ 
    facet_grid(facet ~ .) 

答えて

1

breaksシーケンスを手動で設定する必要があると思います。

brk_vec <- seq.Date(as.Date("2015-09-09"), 
        as.Date("2015-09-19"),by="2 days") 
ggplot(...) + scale_x_date(breaks=brk_vec,date_label="%b %d") 

... lubridateでこれを行うにはいくつかのより多くのエレガントな方法があるかもしれません
関連する問題