1

I'm trying to use dotplots to express both sample data and sample metadata. Both data are continuous, numerical data and grouped into several Accessions. Unfortunately I can't get the continuous 'age' data to work in geom_dotplot unless I change it to categorical data using factor() and I have no idea why

samples.GN.df<- data.frame(
    Protein1 = sample(1:30),
    Accession = sample(c("yes", "no"), 30, replace = TRUE),
    Age = sample(10:39)
    )

This doesn't work:

ggplot(samples.GN.df, aes(y=Protein1, x=Accession))+
   geom_dotplot(binaxis = 'y', stackdir = 'center', mapping = aes(fill = Age))

This does (although the dots no longer stack neatly but I can solve that next):

ggplot(samples.GN.df, aes(y=Protein1, x=Accession))+
   geom_dotplot(binaxis = 'y', stackdir = 'center', mapping = aes(fill = factor(Age)))

I've tried various things to get it to work as continuous rather than discrete data but to no avail, it just comes up as all black, not even an error message to point me in the right direction.

Any help on this would be gratefully received!

(edited to add sample data)

Phil Lewis
  • 33
  • 4
  • 3
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 27 '18 at 17:29
  • Sample data added, thanks! – Phil Lewis Jun 28 '18 at 07:10

1 Answers1

1

You can just add a group into the main mapping and continuous fill mapping into geom_dotplot:

ggplot(samples.GN.df, aes(y=Protein1, x=Accession, group=factor(Age)) ) +
 geom_dotplot(aes(fill=Age ), binaxis = 'y', stackdir = 'center')
Lstat
  • 1,450
  • 1
  • 12
  • 18
  • 1
    Unfortunately this doesn't work on real data where dots overlap, sorry! My fault for insufficient sample data – Phil Lewis Jun 28 '18 at 14:50