I want to create a plot in ggplot for a box plot and a line plot in the same figure. I have a data frame which looks like the following:
Lambda | means | theorMean
1 0.1 10.07989 10
2 0.1 10.55681 10
3 0.1 10.26660 10
4 0.1 10.29234 10
5 0.1 10.07754 10
...
The means
are sample means and the theoretical means are theorMeans
. I want to plot the distribution of the sample means by box plots, while the theoretical means using a straight line.
This is what I have so far ...
library(ggplot2)
library(scales)
p <- ggplot(summ, aes(x=factor(Lambda), y=means)) +
geom_boxplot() +
geom_line(data=summ, aes(x=log10(Lambda), y=means))
The problem is that, for a box plot or a violin plot, I need to use the x axis as a factor. On the other hand, I need the x axis to be a number. I basically want to fit a theoretical line, to the box plots I generate. How can I possible do this?