plot,distribution,density-plot

hist is a nice way to see a distribution. See here for details.

r,ggplot2,quantile,density-plot

You can calculate the quantiles beforehand. Using your example data: library (dplyr) d2 <- df.example %>% group_by(model, type) %>% summarize(lower = quantile(value, probs = .025), upper = quantile(value, probs = .975)) And then plot like this: ggplot(df.example, aes(x = value)) + facet_grid(type ~ model) + geom_density(aes(fill = model, colour =...

r,ggplot2,histogram,curve,density-plot

Use stat_density instead of geom_density like this: ggplot(dataset, aes(x=age)) + geom_histogram(aes(y=..density..), colour="black", fill="white") + stat_density(colour="blue", geom="line", position="identity") + stat_function(fun=dnorm, args=list(mean=mean(dataset_with_victims$TV_Alter), sd=sd(dataset_with_victims$TV_Alter))) + stat_function(fun=dgamma, args=list(shape=mean(dataset_with_victims$TV_Alter)^2/sd(dataset_with_victims$TV_Alter)^2,...

r,plot,postscript,eps,density-plot

Read the help page: ?plot.density zero.line.......logical; if TRUE, add a base line at y = 0 I will admit that I didn't discover this by reading the help page. I had looked at the code for density.default, found nothing useful, then tried plot.density, got the nothing, found message, and then...

r,ggplot2,histogram,density-plot

Fitting a distribution function does not happen by magic. You have to do it explicitly. One way is using fitdistr(...) in the MASS package. library(MASS) # for fitsidtr(...) # excellent fit (of course...) ggplot(df, aes(x = x)) + geom_histogram(aes(y=..density..),colour = "black", fill = "white", binwidth = 0.01)+ stat_function(fun=dbeta,args=fitdistr(df$x,"beta",start=list(shape1=1,shape2=1))$estimate) # horrible...

r,ggplot2,kernel-density,density-plot

Like this? ggplot() + geom_density(aes(x=x), fill="red", data=vec1, alpha=.5) + geom_density(aes(x=x), fill="blue", data=vec2, alpha=.5) EDIT Response to OPs comment. This is the idiomatic way to plot multiple curves with ggplot. gg <- rbind(vec1,vec2) gg$group <- factor(rep(1:2,c(2000,3000))) ggplot(gg, aes(x=x, fill=group)) + geom_density(alpha=.5)+ scale_fill_manual(values=c("red","blue")) So we first bind the two datasets together, then...

r,ggplot2,histogram,category,density-plot

I made up some data for illustration: head(iris) table(iris$Species) df <- iris df$Species2 <- ifelse(df$Species == "setosa", "blue", ifelse(df$Species == "virginica", "red", "")) library(ggplot2) p <- ggplot(df, aes(x = Sepal.Length, colour = (Species == "setosa"))) p + geom_density() # Your example # Now let's choose the other created column p...

There are a couple of questions that show this ... here and here, but they calculate the density prior to plotting. This is another way, more complicated than required im sure, that allows ggplot to do some of the calculations for you. # Your data set.seed(100) amount_spent1 <- data.frame(amount_spent=rnorm(1000, 500,...

How about using stat_density directly ggplot(movies, aes(x = rating)) + stat_density(geom="line") ...

If you set pm3d, this style is used for all plots unless you explicitely specify a different plotting style. So you must use splot "file.txt" u (fact1)*(($1)**(-1.5)):(fact2)*(($2)**(-1.5)):6 ,\ "line.txt" with lines in order to plot line.txt as line: ...

r,ggplot2,histogram,density-plot

the problem is that ggplot doesnt understand the data the way you input it, you need to reshape it like so (I am not a regex-master, so surely there are better ways to do is): df <- read.table(header = TRUE, text = " binRange Frequency 1 (0,0.025] 88 2 (0.025,0.05]...

r,smooth,smoothing,density-plot

you can make you density plot smoother by increasing the bandwidth (bw) plot(density(x$PLCO2, bw = bw_bigger)) ...

r,scatter-plot,kernel-density,density-plot

Seems like you want a filled contour rather than jus a contour. Perhaps library(RColorBrewer) library(MASS) greyscale <-brewer.pal(5, "Greys") x <- rnorm(20000, mean=5, sd=4.5); x <- x[x>0] y <- x + rnorm(length(x), mean=.2, sd=.4) z <- kde2d(x, y, n=100) filled.contour(z, nlevels=4, col=greyscale, plot.axes = { axis(1); axis(2) #points(x, y, pch=".", col="hotpink")...

This illustrates the use of approxfun: > Af <- approxfun(d$x, d$y) > Af(val) [1] 2.348879 > plot(d( + > plot(d) > points(val,Af(val) ) > png();plot(d); points(val,Af(val) ); dev.off() ...