Skip to content

Instantly share code, notes, and snippets.

@sicarul
Created March 14, 2021 05:19
Show Gist options
  • Save sicarul/357633195271810da319a24cec2b29ab to your computer and use it in GitHub Desktop.
Save sicarul/357633195271810da319a24cec2b29ab to your computer and use it in GitHub Desktop.
GGplot test grafico densidad
library(ggplot2)
library(dplyr)
data_normal = rnorm(10000, mean=1000, sd=10)
df = data.frame(Datos=data_normal)
ggplot(df, aes(Datos)) +
theme_minimal() +
geom_area(data = filter(df, Datos>=980), stat="density", fill="#990000", alpha=0.3) +
geom_density(stat="density") +
xlim(970,1030) + theme(
axis.line = element_line(size=1),
axis.ticks = element_line(size = 1),
axis.ticks.length=unit(.25, "cm")
) +
annotate("text", x = 1000, y = 0.005, label = paste0("La probabilidad es de ", as.character(nrow(filter(df,Datos>980))/nrow(df))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment