0

I want to plot the percentage distribution of four different habitat types of male bats during morning trips using ggplot.

My code is the following:

ggplot(subset(random_df_morn[which(random_df_morn$Sex =="male"),]), aes(x = daytime, fill=biotop_new, stat="bin"), main="morning")+ geom_histogram()

But on the y-axis appears "count" instead of "percentage".

What i added was:

+ geom_bar(aes(y = (..count..)/sum(..count..))) +  scale_y_continuous(labels=percent)

But as the "count" was 600, now the percentage is also limited at 60%. But what I need or my purpose are the distributions on a 100% scale.

How can I set the y-axis to 100% instead of the 60%?.

Thank you very much for any help.

aosmith
  • 34,856
  • 9
  • 84
  • 118
rickie
  • 21
  • 1
  • 6
  • Could you provide an example of the type of graph you want, just for clarification? Anyways, I think the top answer on this question (http://stackoverflow.com/questions/21061653/creating-a-density-histogram-ggplot2) should point you in the right direction. – BarkleyBG May 31 '16 at 16:04

1 Answers1

0

Your question was partially answered here. You can simply use the limits parameter within the scale_y_continuous function. Here's a reproducible example using mtcars

library(ggplot2)
library(scales)
ggplot(mtcars, aes(x = factor(hp))) +  
  geom_bar(aes(y = (..count..)/sum(..count..))) + 
  scale_y_continuous(labels = percent, limits = c(0,1))

enter image description here

Community
  • 1
  • 1
jroberayalas
  • 969
  • 7
  • 23