density-plot

Plot median values on top of a density distribution

十年热恋 提交于 2019-12-01 04:50:24
问题 I'm trying to plot the median values of some data on a density distribution using the ggplot2 R library. I would like to print the median values as text on top of the density plot. You'll see what I mean with an example (using the "diamonds" default dataframe): I'm printing three itmes: the density plot itself, a vertical line showing the median price of each cut, and a text label with that value. But, as you can see, the median prices overlap on the "y" axis (this aesthetic is mandatory in

R density plot y axis larger than 1

↘锁芯ラ 提交于 2019-12-01 01:36:14
I want a density plot, and here is the code: d = as.matrix(read.csv(file = '1.csv')) plot(density(d)) my data is a list of number. What I don't understand is that the value of y axis large than 1 I think there is something wrong and search the internet, but i can't find any resource, Can you guys help me? enter image description here here is the data: link: http://pan.baidu.com/s/1hsE8Ony password:7a4z G5W There is nothing wrong with the density being greater than 1 at some points. The area under the curve must be 1, but at specific points the density can be greater than 1. For example, dnorm

Multiple Groups in geom_density() plot

邮差的信 提交于 2019-11-30 19:39:11
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 MidWest Region is the variable, so there is a South and NorthEast value as well, code is below: ggplot(d, aes(x=d$MEI, group=d$region)) + geom_density(adjust=2) + xlab("MEI") + ylab("Density") a step closer Try following: ggplot() + geom_density(data=ddf, aes(x=MEI, group=Region, fill=Region),alpha=0.5, adjust=2) + xlab("MEI") + ylab("Density") If you only want color and no fill:

Multiple Groups in geom_density() plot

走远了吗. 提交于 2019-11-30 04:27:05
问题 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 MidWest Region is the variable, so there is a South and NorthEast value as well, code is below: ggplot(d, aes(x=d$MEI, group=d$region)) + geom_density(adjust=2) + xlab("MEI") + ylab("Density") a step closer 回答1: Try following: ggplot() + geom_density(data=ddf, aes(x=MEI, group

The difference between geom_density in ggplot2 and density in base R

房东的猫 提交于 2019-11-29 15:20:56
I have a data in R like the following: bag_id location_type event_ts 2 155 sorter 2012-01-02 17:06:05 3 305 arrival 2012-01-01 07:20:16 1 155 transfer 2012-01-02 15:57:54 4 692 arrival 2012-03-29 09:47:52 10 748 transfer 2012-01-08 17:26:02 11 748 sorter 2012-01-08 17:30:02 12 993 arrival 2012-01-23 08:58:54 13 1019 arrival 2012-01-09 07:17:02 14 1019 sorter 2012-01-09 07:33:15 15 1154 transfer 2012-01-12 21:07:50 where class(event_ts) is POSIXct . I wanted to find the density of bags at each location in different times. I used the command geom_density(ggplot2) and I could plot it very nice. I

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

懵懂的女人 提交于 2019-11-29 09:34:47
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 yval , which I don't have (it's just a vector of 1000 numbers). Any ideas on how I could do this? Two other related questions: Is it possible to do the same thing for a cumulative density function (I'm currently using stat_ecdf to generate one), or shade it at all? Is there any way to edit geom_vline so it will only go up to the height of the

Scatter plot with density in Matlab

回眸只為那壹抹淺笑 提交于 2019-11-28 10:03:16
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 awful. Is there another way to plot scatter density plots? Is there really no Matlab function for it? If not, which program could I use to easy generate such a plot? A mix between this two examples: Example2 http://www.bcgsc.ca/people/malachig/htdocs/alexa_platform/alexa_seq/FL_Trans/images/HS1361/ExonRegionVsGeneExpression_Log2.jpeg Thanks to @Emil

Legend does not show line type in ggplot2 density plot

回眸只為那壹抹淺笑 提交于 2019-11-28 08:23:00
问题 I created a density plot with ggplot from a dataframe with 3 variables. One density line is dotted, but the legend shows a solid line for this line. The data looks like this: > head(df) R1 R2 R3 1 0.085383867 0.04366546 0.055320885 2 0.059148932 0.03477045 0.040804048 3 -0.181279986 -0.10189900 -0.097218145 4 0.002307494 -0.01137235 -0.003585813 5 -0.047816198 -0.04932982 -0.009389939 6 0.030535090 0.02544292 0.017650949 The code for the plot is: ggplot(data=df)+ stat_density(aes(x=R1, colour

Any suggestions for how I can plot mixEM type data using ggplot2

匆匆过客 提交于 2019-11-27 04:34:09
I have a sample of 1m records obtained from my original data. (For your reference, you may use this dummy data that may generate approximately similar distribution b <- data.frame(matrix(rnorm(2000000, mean=c(8,17), sd=2))) c <- b[sample(nrow(b), 1000000), ] ) I believed the histogram to be a mixture of two log-normal distributions and I tried to fit the summed distributions using EM algorithm using the following code: install.packages("mixtools") lib(mixtools) #line below returns EM output of type mixEM[] for mixture of normal distributions c1 <- normalmixEM(c, lambda=NULL, mu=NULL, sigma

Scatter plot with density in Matlab

亡梦爱人 提交于 2019-11-27 03:23:00
问题 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 awful. Is there another way to plot scatter density plots? Is there really no Matlab function for it? If not, which program could I use to easy generate such a plot? A mix between this two examples: (source: bcgsc.ca) 回答1: Thanks to @Emil Albert