Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hi everyone,
Having a bit of an issue overlaying a normal distribution curve on a histogram visual, using R scripts.
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset <- data.frame(Ratings)
# dataset <- unique(dataset)
# Paste or type your script code here:
library(ggplot2)
ggplot(data=dataset,aes(x=dataset$Ratings)) +
geom_histogram(aes(y=..density..),col="#ffffff",fill="#bfd730") +
labs(title="Employee 2019 Performance Rating", x="Performance Ratings", y="Frequency") +
geom_density(col=2)
#Adding Normal Curve
ratings_norm_curve=rnorm(length(Ratings),mean(Ratings),sd(Ratings))
#Adding it to Histogram
lines(density(ratings_norm_curve, adjust = 2), col="blue", lwd=2)What might I be doing wrong here?
Solved! Go to Solution.
Hi @Anonymous ,
Sorry to reply late. Please check whether this could meet your requirements:
library(ggplot2)
ggplot(data=dataset,aes(x=dataset$Ratings)) +
geom_histogram(aes(y=..density..),col="#ffffff",fill="#bfd730") +
labs(title="Employee 2019 Performance Rating", x="Performance Ratings", y="Frequency") +
geom_density(col=2) +
stat_function(fun = dnorm,
args = list(mean = mean(dataset$Ratings, na.rm = TRUE),
sd = sd(dataset$Ratings, na.rm = TRUE)),
colour = 'blue')
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Sorry to reply late. Please check whether this could meet your requirements:
library(ggplot2)
ggplot(data=dataset,aes(x=dataset$Ratings)) +
geom_histogram(aes(y=..density..),col="#ffffff",fill="#bfd730") +
labs(title="Employee 2019 Performance Rating", x="Performance Ratings", y="Frequency") +
geom_density(col=2) +
stat_function(fun = dnorm,
args = list(mean = mean(dataset$Ratings, na.rm = TRUE),
sd = sd(dataset$Ratings, na.rm = TRUE)),
colour = 'blue')
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Why the frequency shown in decimals (x axis)?
@Icey is it possible to show the count of frequency on the x-axis of this code?
Yes thank you so much!!! 🙂
Hi @Anonymous ,
Please share me some dummy sample data, not real data, for test.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 38 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 68 | |
| 65 | |
| 30 | |
| 26 | |
| 25 |