0

I have data that looks like this

    df <- data.frame(c("Cell1","Cell2","NK-Cell"),c("K","L","S","L","K","S","S","L","K"),abs(log2(abs(rnorm(180)))))    
colnames(df) <- c("ctype","tissue","exp")

I'm trying to create a plot that looks like this. enter image description here

neversaint
  • 60,904
  • 137
  • 310
  • 477
  • 2
    Your example data only contains data for the diagonal of that example plot.... – mnel Aug 20 '13 at 05:43
  • Oops. I updated the code. – neversaint Aug 20 '13 at 05:47
  • 4
    -1. I'd like to think that after [a very similar question](http://stackoverflow.com/questions/14623348/how-to-use-facet-to-create-multiple-density-plot-in-ggplot) on facetting and density plots and [many other simlar facet-related questions](http://stackoverflow.com/search?q=user%3A67405+%5Bggplot%5D+facet) from you, you should at least show the code you've tried... let alone be able to learn something out of the questions you ask. – Arun Aug 20 '13 at 07:17
  • See the Facets section: http://www.cookbook-r.com/Graphs/ – Stéphane Laurent Aug 20 '13 at 09:22

1 Answers1

5

General idea in this situation would be to use faceting to get this kind of plot.

ggplot(df,aes(exp))+geom_density()+facet_grid(tissue~ctype)

There are two empty plots because there are no Cell2 values for the tissue S and no NK-Cell values for tissue L.

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201