1
genocount <-ggplot(SNPs, aes(genotype))
genocount + geom_bar()

Creates this Bar Chart:

enter image description here

I would like to be able to display the percentage contribution per chromosome to each genotype in a stacked orientation (those are displayed along the x axis). I've tried some methods that I've seen suggested by others, but they return different errors...I'm not sure if there's an incompatibility with my data set or if it's something else.

Thanks for your help!

library(scales)

ggplot(SNPs, aes(genotype))
    genocount + geom_bar(aes(position = "fill", fill = chromosome))+
    geom_text(aes(label = percent(chromosome/sum(chromosome))))
    scale_y_continuous(labels = percent_format())
neilfws
  • 32,751
  • 5
  • 50
  • 63
  • Please try to include a [reproducible example](https://stackoverflow.com/q/5963269/1222578) of your data, this will make it much easier to answer your question. – Marius Feb 12 '18 at 04:12
  • In this case what would that mean? The original parameters for the ggplot or alternative plots that I've created from the data?? Thanks! – Rachel Brody Feb 12 '18 at 18:33

1 Answers1

0

I know exactly what you mean.

In the case of a bar chart the code is the following

ggplot(mydf) +
geom_bar(aes(x = var1,y = (..count..)/sum(..count..)),
stat = "count",position = "identity")

In the case of an histogram, the code is the following:

ggplot(data = df) +
geom_histogram(aes(x = var1, y = (..count..)/sum(..count..)),
position = "identity")

Don't ask me what is ..count.. I only know it is a black magic that works

Seymour
  • 3,104
  • 2
  • 22
  • 46