Ggplot2: placing multiple mailboxes as time series

I would like to create a multi-dimensional time series boxplot with ggplot2, and I need to have an x ​​axis that positions the boxes based on their associated dates.

I found two entries on this subject: one Timeline plot with groups using ggplot2 , but the x axis is not scale_x_axis, so in my case the plot is offset. The other is ggplot2: a boxofot multiplier with the scale_x_date axis in R , but the person uses an interaction function that I do not use in my case.

Here is an example of a file and my code:

dtm <- read.table(text="date ruche mortes trmt      
03.10.2013     1      8   P+        
04.10.2013     1      7   P+        
07.10.2013     1     34   P+       
03.10.2013     7     16   P+       
04.10.2013     7     68   P+       
07.10.2013     7    170   P+
03.10.2013     2      7   P-        
04.10.2013     2      7   P-       
07.10.2013     2     21   P-      
03.10.2013     5      8   P-       
04.10.2013     5     27   P-      
07.10.2013     5     24   P- 
03.10.2013     3     15    T       
04.10.2013     3      6    T    
07.10.2013     3     13    T    
03.10.2013     4      6    T    
04.10.2013     4     18    T    
07.10.2013     4     19    T ", h=T)

require(ggplot2)
require(visreg)
require(MASS)
require(reshape2)
library(scales)

dtm$asDate = as.Date(dtm[,1], "%d.%m.%Y")

## Plot 1: Nearly what I want but is biased by the x-axis format where date should not be a factor## 

p2<-ggplot(data = dtm, aes(x = factor(asDate), y = mortes)) 
p2 +  geom_boxplot(aes(fill = factor(dtm$trmt))) 

## Plot 2: Doesn't show me what I need, ggplot apparently needs a factor as x## 

p<-ggplot(data = dtm, aes(x = asDate, y = mortes)) 
p +  geom_boxplot(aes( group = asDate, fill=trmt) ) `

Can someone help me with this problem please?

+4
source share
1

, ?

enter image description here

:

p <- ggplot(data = dtm, aes(x = asDate, y = mortes, group=interaction(date, trmt)))
p +  geom_boxplot(aes(fill = factor(dtm$trmt)))

, interaction(date, trmt), , asDate , ggplot . - x, + scale_x_date().

+3

All Articles