Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 135 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 716 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 says “Linear Relation Display” then we can use the below command −ggplot(df,aes(X,Y))+geom_point()+labs(caption="Note: Linear Relation Display")ExampleFollowing snippet creates a sample data frame −x

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 2K+ 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 below example.ExampleFollowing snippet creates a sample data frame −Height

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 4K+ 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 packages in windows operating system −.libPaths() OutputIf you execute the given snippet, it generates the following Output −[1] "C:/Users/Nizam/Documents/R/win-library/4.0" [2] "C:/Program Files/R/R-4.0.4/library"Use the below mentioned code to find the location of installed packages in windows operating system −installed.packages()[1:20, ] OutputIf you execute all the above given snippets as a single ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 566 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 we can make all the values unique by using the below command −df[]

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 4K+ 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 snippet creates a sample data frame −ID

Read More

How to find the frequency with subsetting in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 439 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 in the below examples.Example 1Following snippet creates a sample data frame −head(ChickWeight, 20)OutputThe following dataframe is created − weight Time Chick Diet 1   42   0   1     1 2   51  2    1     1 3   59  4    1     1 4 ...

Read More

How to remove question mark from corrplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 2K+ 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 and set it to blank as shown in the below Example.ExampleFollowing snippet creates a sample matrix −M

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 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 below to understand how it can be done.Example 1Following snippet creates a sample matrix −M1

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 3K+ 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 given below −TABLE

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 6K+ 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 below command −with(df,table(F1,F2))Example 1Following snippet creates a sample data frame −Group

Read More
Showing 1341–1350 of 1,958 articles
« Prev 1 133 134 135 136 137 196 Next »
Advertisements