Установка плотности изгибается к гистограмме в R

То, что Вы имеете, должно работать, но может быть уменьшено до:

select * from table where concat_ws(' ',first_name,last_name) 
like '%$search_term%';

можно ли обеспечить имя в качестве примера и критерий поиска, где это не работает?

85
задан Gregor 16 November 2012 в 16:38
поделиться

3 ответа

Если я правильно понял ваш вопрос, то вы, вероятно, захотите оценить плотность вместе с гистограммой:

X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))
hist(X, prob=TRUE)            # prob=TRUE for probabilities not counts
lines(density(X))             # add a density estimate with defaults
lines(density(X, adjust=2), lty="dotted")   # add another "smoother" density

Отредактируйте немного позже:

Вот немного более нарядная версия :

X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))
hist(X, prob=TRUE, col="grey")# prob=TRUE for probabilities not counts
lines(density(X), col="blue", lwd=2) # add a density estimate with defaults
lines(density(X, adjust=2), lty="dotted", col="darkgreen", lwd=2) 

вместе с графиком, который он производит:

enter image description here

149
ответ дан 24 November 2019 в 08:12
поделиться

Such thing is easy with ggplot2

library(ggplot2)
dataset <- data.frame(X = c(rep(65, times=5), rep(25, times=5), 
                            rep(35, times=10), rep(45, times=4)))
ggplot(dataset, aes(x = X)) + 
  geom_histogram(aes(y = ..density..)) + 
  geom_density()

or to mimic the result from Dirk's solution

ggplot(dataset, aes(x = X)) + 
  geom_histogram(aes(y = ..density..), binwidth = 5) + 
  geom_density()
29
ответ дан 24 November 2019 в 08:12
поделиться

Вот как я это делаю:

foo <- rnorm(100, mean=1, sd=2)
hist(foo, prob=TRUE)
curve(dnorm(x, mean=mean(foo), sd=sd(foo)), add=TRUE)

Дополнительное упражнение - сделать это с помощью пакета ggplot2 ...

26
ответ дан 24 November 2019 в 08:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: