0
votes

I created a barplot using ggplot in which the x-axis represents a number in acending order and each number has is own percentage. I would like to normalized the observed barplot (Gaussian) in order to compare the two barplots. someone know how to do it? Here is my code:

lemon_imp_05 = subset(Lemon_brevante_data,Lemon_brevante_data$Block == "IMP-05")
  S = lemon_imp_05$percentage
  names(S) = lemon_imp_05$count
  barplot(S, main = 'Block IMP-05 Loam',
          xlab= 'Count(N.fruits/carton)',ylab = 'percentage(%)', col = "green")

The result is a non normal distribution bar plot, but I want to force a normal distribution on the observed barplot (don't know how to add picture of the current result). any suggestions? Thanks

1
Normalize your data. barplot(S / sum(S), ...). Though this would be a sum-to-one normalization, not a Gaussian normalization. You could use scale(S) instead if you want to center and scale the vector. If you edit your question, in the edit bar there's an "add image" button.Gregor Thomas
Do I need to write: barplot(scale(S),...) ? and in barplot(S / sum(S),...) I can't see any difference. or maybe I don't write it in the right positionErez Kauffman
Could you share some sample data? Something like dput(S[1:10]) for the first 10 values would be great - it will be copy/pasteable and include all structure and class information.Gregor Thomas

1 Answers

0
votes

Do you want to plot the densitity distribution of your empirical data, and compare it to a normal distribution with same mean and sd?

plot(density(y), ylim=c(0, .5), lwd=2)
curve(dnorm(x, mean=mean(y), sd=sd(y)), add=TRUE, lwd=2, lty=2, col=2)

enter image description here

Like this?


Data:

set.seed(42)
y <- rnorm(1e2, mean=1.5, sd=.8)

Or use hist.

h <- hist(y, freq=F, breaks="FD")
curve(dnorm(x, mean=mean(y), sd=sd(y)), add=TRUE, lwd=2, lty=2, col=2)

enter image description here

## stored values
h
# $breaks
# [1] -1.0 -0.5  0.0  0.5  1.0  1.5  2.0  2.5  3.0  3.5
# 
# $counts
# [1]  2  2  6 15 21 23 17 11  3
# 
# $density
# [1] 0.04 0.04 0.12 0.30 0.42 0.46 0.34 0.22 0.06
# 
# $mids
# [1] -0.75 -0.25  0.25  0.75  1.25  1.75  2.25  2.75  3.25
# 
# $xname
# [1] "y"
# 
# $equidist
# [1] TRUE
# 
# attr(,"class")
# [1] "histogram"