Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...