Displayr can create density plots to help you visualize the distribution of your data. You can do this through our built-in density plot visualization (see How to Create a Density Plot) or by using custom R code in a Calculation, which is covered in this post.
This post will use a numeric variable, such as the number of days to purchase a product:
to create a Density plot, showing the distribution and any peaks:
Requirements
You will need a numeric variable in your Data Sets tree. Numeric variables are represented by a "2" next to their name:
Method
- From the toolbar, go to Calculation > Custom Code.
- In the object inspector, go to Data > R Code > Edit Code and paste in the following code and click Calculate.
#create density plot - change Days to the name of your numeric variable
plot(density(Days, from = 0),
main = "Density plot", #this is the title of the plot
xlab = "Number of days since trial started") #this is the title of the x-axis
OPTIONAL:
You can modify the R code slightly to remove outliers from your density plot output or reduce the date range to make it easier to determine where the peak occurs. In the example below, data is plotted only for the values from 0 to 100 days (to = 100) and the bandwidth has been changed to estimate the density (adjust = 0.2).
#create density plot - change Days to the name of your numeric variable
plot(density(Days, from = 0, to = 100, adjust = 0.2), #plot values 0-100 and adjust bandwidth
main = "Density plot - Up to 100 days (86% of data)", #this is the title of the plot
xlab = "Number of days since trial started") #this is the title of the x-axis
Next
How to Create a Heated Density Plot