Questions tagged [density-plot]

A density-plot illustrates the relative likelihood of a variable to take on a given value.

A density-plot illustrates the relative likelihood of a variable to take on a given value. It is the line equivelant of a .

Density-plots in several languages:

  • R: plot(density(x))
  • Wolfram: DensityPlot[f,{x,xmin,xmax},{y,ymin,ymax}]

Links:

599 questions
131
votes
4 answers

How can I make a scatter plot colored by density?

I'd like to make a scatter plot where each point is colored by the spatial density of nearby points. I've come across a very similar question, which shows an example of this using R: R Scatter Plot: symbol color represents number of overlapping…
2964502
  • 4,301
  • 12
  • 35
  • 55
90
votes
8 answers

How to overlay density plots in R?

I would like to overlay 2 density plots on the same device with R. How can I do that? I searched the web but I didn't find any obvious solution. My idea would be to read data from a text file (columns) and then…
pasta
  • 1,466
  • 5
  • 15
  • 25
64
votes
6 answers

seaborn distplot / displot with multiple distributions

I am using seaborn to plot a distribution plot. I would like to plot multiple distributions on the same plot in different colors: Here's how I start the distribution plot: import numpy as np import pandas as pd from sklearn.datasets import…
Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60
31
votes
5 answers

Plot a histogram such that the total height equals 1

This is a follow-up question to this answer. I'm trying to plot normed histogram, but instead of getting 1 as maximum value on y axis, I'm getting different numbers. For array k=(1,4,3,1) import numpy as np def plotGraph(): import…
user40
  • 1,361
  • 5
  • 19
  • 34
18
votes
1 answer

How to shade part of a density curve in ggplot (with no y axis data)

I'm trying to create a density curve in R using a set of random numbers between 1000, and shade the part that is less than or equal to a certain value. There are a lot of solutions out there involving geom_area or geom_ribbon, but they all require a…
user3711502
  • 412
  • 5
  • 15
15
votes
2 answers

geom_density y-axis goes above 1

I think this might partly be an R question and partly a statistics question, so please excuse me if there is a better place for it (if so, please let me know where). Let's say I have a dataset my_measurements like this: >…
hpy
  • 1,989
  • 7
  • 26
  • 56
14
votes
1 answer

ggplot_stat_density2d plots for ecological distribution

I'm trying to plot ecological distribution of some species of organisms I'm studying over the Arabian/Persian Gulf. Here is a sample of a code I've tried: Backround layer library(ggplot2) library(ggmap) nc <- get_map("Persian Gulf", zoom = 6,…
Hammao
  • 801
  • 1
  • 9
  • 28
14
votes
3 answers

R: How to : 3d Density plot with gplot and geom_density

I'm trying to combine multiple density plots with overlay. ggplot and geom_density do the job, but the densities are stacked on top of each other. ggplot(all.complete, aes(x=humid_temp)) + geom_density(aes(group=height, colour=height,…
rafaelvalle
  • 6,683
  • 3
  • 34
  • 36
12
votes
2 answers

Scatter plot with density in Matlab

I would like to plot data set 1 and data set 2 in one plot vertical. Unfortunately the data is huge, so it is just a smear of points and can't see the density. I tried hist3 and other suggestions but it overwrites my data sets and the binning looks…
C.Colden
  • 627
  • 1
  • 8
  • 28
11
votes
1 answer

Drawing histograms or densities along smooth curves using ggplot2

Is there a general way to draw densities (violin plots) or histograms showing the distribution of x along a smooth (x,y) curve? I use this approach to show the marginal distribution of x when there are multiple groups (e.g., different curves on one…
Frank Harrell
  • 1,954
  • 2
  • 18
  • 36
11
votes
2 answers

Multiple Groups in geom_density() plot

I am trying to plot 3 groups in one geom_density()plot. The data is in long format: MEI Count Region -2.031 10 MidWest -1.999 0 MidWest -1.945 15 MidWest -1.944 1 MidWest -1.875 6 MidWest -1.873 10 MidWest -1.846 18 …
Methexis
  • 2,739
  • 5
  • 24
  • 34
10
votes
2 answers

Compute area under density estimation curve, i.e., probability

I have a density estimate (using density function) for my data learningTime (see figure below), and I need to find probability Pr(learningTime > c), i.e., the the area under density curve from a given number c (the red vertical line) to the end of…
Eric
  • 149
  • 1
  • 1
  • 7
9
votes
1 answer

Adding a density line to a histogram with count data in ggplot2

I want to add a density line (a normal density actually) to a histogram. Suppose I have the following data. I can plot the histogram by ggplot2: set.seed(123) df <- data.frame(x = rbeta(10000, shape1 = 2, shape2 = 4)) ggplot(df, aes(x = x)) +…
HBat
  • 4,873
  • 4
  • 39
  • 56
8
votes
1 answer

How to plot (x,y,z) points showing their density

My data file is a set of (x,y,z) points located around the axis origin. They represent points where a kind of measure has failed. These points are in this link. Gnuplot can plot them, set encoding iso_8859_1 set term postscript eps enhanced color…
user1993416
  • 698
  • 1
  • 9
  • 28
8
votes
1 answer

How does ggplot2 density differ from the density function?

Why do the following plots look different? Both methods appear to use Gaussian kernels. How does ggplot2 compute a density? library(fueleconomy) d <- density(vehicles$cty, n=2000) ggplot(NULL, aes(x=d$x, y=d$y)) + geom_line() +…
Megatron
  • 15,909
  • 12
  • 89
  • 97
1
2 3
39 40