Если вы знакомы с ggplot, вы можете сделать следующее:
set.seed(124)
library(ggplot2)
library(tidyr)
Sample100 <- replicate(100, matrix(data=rpois(100, lambda = 3),ncol = 1), simplify = TRUE)
Samplelong <- gather(as.data.frame(Sample100))
ggplot(Samplelong, aes(x = value)) +
geom_density(aes(group = key)) +
labs(x = "y", #labs function overides labels on the plot
y = "P(y)",
title = "Probability density function for 100 sample") +
theme_classic() + # This changes the theme to look similar to base r plot theme
#theme function allows you to modify plot further, everyting from size
# fonts, angles, axis.
theme(plot.title = element_text(hjust = 0.5, #hjust - horizontal shift
face = "bold")) + . # face - the print for plot.title is set to bold
scale_x_continuous(expand = c(0,0)) + #for the continuous x axis, limit expansion to 0 on both ends
scale_y_continuous(expand = c(0,0)) #for the continuous y axis, limit expansion to 0 on both ends
. Для справки вы строите следующее:
ggplot(Samplelong, aes(x = value)) +
geom_density() +
labs(x = "y", y = "P(y)", title = "Probability density function for 100 sample") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0))
, если ggplot2 смущает вас, просто не торопитесьс попыткой сделать график красивым, для большинства целей хорошо.
ggplot(Samplelong, aes(x = value)) +
geom_density(aes(group = key)) +
labs(x = "y", #labs function overides labels on the plot
y = "P(y)",
title = "Probability density function for 100 sample")