density-plot

draw line on geom_density_ridges

点点圈 提交于 2020-05-28 04:13:27
问题 I am trying to draw a line through the density plots from ggridges library(ggplot2) library(ggridges) ggplot(iris, aes(x = Sepal.Length, y = Species)) + geom_density_ridges(rel_min_height = 0.01) Indicating the highest point and label the value of x at that point. Something like this below. Any suggestions on accomplishing this is much appreciated 回答1: One neat approach is to interrogate the ggplot object itself and use it to construct additional features: # This is the OP chart library

draw line on geom_density_ridges

萝らか妹 提交于 2020-05-28 04:12:58
问题 I am trying to draw a line through the density plots from ggridges library(ggplot2) library(ggridges) ggplot(iris, aes(x = Sepal.Length, y = Species)) + geom_density_ridges(rel_min_height = 0.01) Indicating the highest point and label the value of x at that point. Something like this below. Any suggestions on accomplishing this is much appreciated 回答1: One neat approach is to interrogate the ggplot object itself and use it to construct additional features: # This is the OP chart library

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

烂漫一生 提交于 2020-05-10 10:06:07
问题 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)) + geom_histogram(colour = "black", fill = "white", binwidth = 0.01) I can add a density line using: ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..),colour = "black", fill = "white", binwidth = 0.01) + stat_function(fun = dnorm, args = list

How to overlay density ggplots from different datasets in R?

二次信任 提交于 2020-05-09 10:31:28
问题 I have three ggplots (g1, g2, g3) . They are all from different datasets, and they each have the same xlim and ylim . I would like to plot them all on one page and overlay them. I have only found resources online explaining how to plot multiple density plots from the same dataset on the same page. Is there code I can write so that all subsequent plots are plotted on the same page? 回答1: As @Phil pointed out you can't overlay different plots. However, you can make one plot containing all three

How to overlay density ggplots from different datasets in R?

一个人想着一个人 提交于 2020-05-09 10:31:23
问题 I have three ggplots (g1, g2, g3) . They are all from different datasets, and they each have the same xlim and ylim . I would like to plot them all on one page and overlay them. I have only found resources online explaining how to plot multiple density plots from the same dataset on the same page. Is there code I can write so that all subsequent plots are plotted on the same page? 回答1: As @Phil pointed out you can't overlay different plots. However, you can make one plot containing all three

How to overlay density ggplots from different datasets in R?

梦想的初衷 提交于 2020-05-09 10:31:12
问题 I have three ggplots (g1, g2, g3) . They are all from different datasets, and they each have the same xlim and ylim . I would like to plot them all on one page and overlay them. I have only found resources online explaining how to plot multiple density plots from the same dataset on the same page. Is there code I can write so that all subsequent plots are plotted on the same page? 回答1: As @Phil pointed out you can't overlay different plots. However, you can make one plot containing all three

How to plot the difference between two density distributions

与世无争的帅哥 提交于 2020-01-25 21:55:12
问题 I've trained a model to predict a certain variable. When I now use this model to predict said value and compare this predictions to the actual values, I get the two following distributions. The corresponding R Data Frame looks as follows: x_var | kind 3.532 | actual 4.676 | actual ... 3.12 | predicted 6.78 | predicted These two distributions obviously have slightly different means, quantiles, etc. What I would now like to do is combine these two distributions into one (especially as they are

Plot quantiles of distribution in ggplot2 with facets

有些话、适合烂在心里 提交于 2020-01-23 12:46:11
问题 I'm currently plotting a number of different distributions of first differences from a number of regression models in ggplot. To facilitate interpretation of the differences, I want to mark the 2.5% and the 97.5% percentile of each distribution. Since I will be doing quite a few plots, and because the data is grouped in two dimension (model and type), I would like to define and plot the respective percentiles in the ggplot environment. Plotting the distributions using facets gets me to