
I copied some from the data carrots <- rnorm(100000,5,2) Here's the version like the ggplot2 one I gave only in base R. The only issue with this is that it looks much better if the histogram breaks are aligned, which may have to be done manually (in the arguments passed to hist). Legend('topleft',c('Carrots','Cucumbers'), Xaxt = 'n', yaxt = 'n', # don't add axesįreq = FALSE) # relative, not absolute frequency Plot(histCucumber,xlim = xlim, ylim = ylim, Main = 'Distribution of carrots and cucumbers') Plot(histCarrot,xlim = xlim, ylim = ylim,įreq = FALSE, # relative, not absolute frequency Xlim <- range(histCucumber$breaks,histCarrot$breaks) HistCucumber <- hist(cucumberLengths,plot = FALSE) HistCarrot <- hist(carrotLengths,plot = FALSE) # calculate the histograms - don't plot yet Here is an example of how you can do it in "classic" R graphics: # generate some random data Here's a function I wrote that uses pseudo-transparency to represent overlapping histograms plotOverlappingHist 0 & bhist$counts > 0) ggplot(vegLengths, aes(length, fill = veg)) + Also note that I made it density histograms. You might miss that if you don't really have an idea of what your data should look like. Note that you must change position from the default "stack" argument. Now, if you really did want histograms the following will work. ggplot(vegLengths, aes(length, fill = veg)) + geom_density(alpha = 0.2) # and combine into your new data frame vegLengthsĪfter that, which is unnecessary if your data is in long format already, you only need one line to make your plot. # a variable to identify where they came from later.



# First make a new column in each that will be

# Now, combine your two dataframes into one. So, let's start with something like what you have, two separate sets of data and combine them. If you've been reading on ggplot then maybe the only thing you're missing is combining your two data frames into one long one. That image you linked to was for density curves, not histograms.
