1

I have collected count data highlighting the same thing, but in two different ways. It has been collected on the same dates through a year. I would like to display my collected data in the same plot.

So basically like this Plot multiple boxplot in one graph. enter image description here But maybe where the two box plots are subsummed by a larger box that only has one "entry" to the x-axis at the correct date.

I am able to make the two plots apear on top of each other, but this is not what i desire :)

Two boxplots on top of each other:

enter image description here

ggplot() + geom_boxplot(data=datedata, aes(x=Date, y=Timelinedata1, group=Date) + 
geom_boxplot(data=datedata, aes(x=Date, y=Timelinedata1, group=Date))

Hope you can help.

Kind regards Mathias

Alfonso
  • 644
  • 7
  • 17

1 Answers1

0

How about this? you need the argument position to tell ggplot how to plot data on the same X value. In this case I used position = "dodge" to put them one next to the other.

Since you did not add a minimal reproducible example I had to make an example dataset.

Load libraries

library(reshape2)
library(ggplot2)

Generate example dataset

data1 <- rnorm(100)
data2 <- rnorm(100)
data3 <- rnorm(100)

data.df <- data.frame("1"=data1, "2"=data2, "3"=data3)
plot.df <- melt(data.df)
plot.df$dodge <- c("A","B")
plot.df$dodge <- factor(plot.df$dodge , levels = c("A","B"))

Make plot

ggplot(plot.df) + 
  geom_boxplot(aes(x=variable, y=value, fill = dodge),
               position = "dodge")

enter image description here

Alfonso
  • 644
  • 7
  • 17