Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Data Science by (17.6k points)

enter image description here

Instead of creating different different plots for a data-frame, I want to create a matrix of density plots for a data frame where I can see all the columns in one plot. For creating it separately I am using below code. How can I get all the columns in one plot?

loan_amnt <- density(out_data$loan_amnt)

plot(loan_amnt, main="Loan Amount")

polygon(loan_amnt, col="red", border="blue")

enter image description here

1 Answer

0 votes
by (41.4k points)
edited by

For getting all the columns in one plot you can combine gather() from library dplyr, and facet_grid() or facet_wrap() from ggplot2.

 Gather will regroup all the column names in one variable (values of these variables in a second variable) and then you can build plot with the help of ggplot and then use facet_wrap that will create one plot for each level of the used variable with the column names.

If you want to explore more in R programming then watch this R programming tutorial for beginner:

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...