Nizamuddin Siddiqui has Published 2307 Articles

How to add a caption in a ggplot2 graph in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:52:30

597 Views

To add a caption in a ggplot2 graph in R, we can use labs function. For Example, if we have a data frame called df that contains two columns say X and Y and we want to create scatterplot between X and Y with a caption as a Note that ... Read More

How to change legend for multiple histograms using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:48:50

1K+ Views

If we create histogram for multiple categories using ggplot2 then the legend is generated automatically based on the categories. And if we want to change that legend or create a histogram with different legend values having different colors for histograms then scale_fill_manual function can be used as shown in the ... Read More

How to find the location of installed packages in R in windows operating system?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:45:27

3K+ Views

To find the location of installed packages in R in windows operating system, we can use the command mentioned below −.libPaths()This will return the location of installed packages in the first line and the program files in the second line.Use the below mentioned code to find the location of installed ... Read More

How to make all values in an R data frame unique?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:41:54

339 Views

To make all values in an R data frame unique, we can use make.unique function but firstly we would need to unlist the data frame values and read them with as.character. For Example, if we have a data frame called df that contains duplicate as well as nonduplicate values then ... Read More

How to find the row corresponding to a nearest value in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:40:32

3K+ Views

To find the row corresponding to a nearest value in an R data frame, we can use which.min function after getting the absolute difference between the value and the column along with single square brackets for subsetting the row.To understand how it works, check out the examples given below.Example 1Following ... Read More

How to find the frequency with subsetting in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:36:30

333 Views

The easiest way to find the frequency is to create a table for the provided vector or data frame column and it can be done with table function. But, if the frequency needs to be found with subsetting then subset function and transform function will also be required as shown ... Read More

How to remove question mark from corrplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:35:41

946 Views

When we have NAs present in the data frame or matrix then correlation matrix contains NA values. Now if we create the correlation matrix plot using corrplot function the Output display question marks.If we want to create the correlation matrix without question marks then we can use the na.label argument ... Read More

How to create a block diagonal matrix using a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:24:46

2K+ Views

To create a block diagonal matrix using a matrix in R, we can use bdiag function of Matrix package.For Example, if we have a matrix called M and we want to create block diagonal using M 4 times by using the below command −bdiag(replicate(4, M, simplify=FALSE))Check out the Examples given ... Read More

How to create a table with sub totals for every row and column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:07:25

2K+ Views

The sub totals for every row and column are actually called marginal sums. Therefore, we can use addmargins function to our table to get the sub totals for every row and column.For example, if we have table called TABLE then we can add the sub totals by using the command ... Read More

How to create table of two factor columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 03-Nov-2021 07:03:46

5K+ Views

To create table of two factor columns in an R data frame, we can use table function and with function.For Example, if we have a data frame called df that contains two factor columns say F1 and F2 then we can create table of these two columns by using the ... Read More

Advertisements