Hi, I try to create a histogram to show the distribution of sick days reported by our organization.
below is my code.
ggplot(data,mapping=aes(x=Annualized.Sick.Days,y=..count..,label=..count..,fill=Direct.Indirect))+
geom_histogram(binwidth=10,color="white")+
scale_x_continuous(breaks = seq(30, 100, 10), lim = c(30, 100))+
theme_classic2() +
geom_text(stat="bin", size=2,vjust=0)
Unfortunately, the labels are not in place, it looks there are more data labels than it should be.
Hi!
To help us help you, could you please prepare a repr oducible ex ample (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
FJCC
November 8, 2020, 2:42pm
3
If the following does not solve your problem, please follow nirgrahanuk's advice and provide a reprex.
Notice I put the breaks argument in both geom_histogram and geom_text.
library(ggplot2)
DF <- data.frame(Direct.Indirect=rep(c("Direct","Indirect"),100),
Annualized.Sick.Days=runif(100,30,100))
ggplot(DF,mapping=aes(x=Annualized.Sick.Days,label=..count..,fill=Direct.Indirect))+
geom_histogram(binwidth=10,color="white",breaks = seq(30, 100, 10))+
theme_classic() +
geom_text(stat="bin", size=2,vjust=0,breaks = seq(30, 100, 10),position="stack")
Created on 2020-11-08 by the reprex package (v0.3.0)
system
Closed
November 29, 2020, 2:42pm
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.