Nizamuddin Siddiqui has Published 2307 Articles

How to change the color of gridlines of a ggplot2 graph in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 11:32:22

3K+ Views

To change the color of gridlines of a ggplot2 graph in R, we can use theme function with panel.grid.major and panel.grid.minor arguments where we can set the minor and major gridlines color of the plot panel to desired color.To understand how it can be done, check out the below Example.ExampleFollowing ... Read More

How to change the plot border color of a ggplot2 graph in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 11:25:46

4K+ Views

To change the plot border color of a ggplot2 graph in R, we can use theme function with panel.background argument where we can set the border of the plot panel using element_rect to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample ... Read More

Find the sum of a column values based on another numerical column in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 11:16:35

281 Views

To find the sum of a column values based on another numerical column in R, we can use with function and define the sum by subsetting the column with the help of single square brackets.For Example, if we have a data frame called df that contains two columns say X ... Read More

How to create horizontal line in xyplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 11:03:24

528 Views

To create horizontal line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a horizontal line at Y = 2 then ... Read More

R Programming to find the column name for row maximum in a data.table object.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 10:49:43

337 Views

If we have a data.table object and we want to find the column name for row maximum then we can use max.col function.For Example, if we have a data.table object called DT then we can find the column name for row maximum by using the below command −DT[, names(.SD)[max.col(.SD, ties.method="first")]]Example ... Read More

Remove rows from a data frame that exists in another data frame in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 10:34:33

5K+ Views

To remove rows from a data frame that exists in another data frame, we can use subsetting with single square brackets. This removal will help us to find the unique rows in the data frame based on the column of another data frame.Check out the below Examples to understand how ... Read More

Add values in sequence to the previous value with a constant.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 10:15:59

441 Views

To add values in sequence to the previous value with a constant, we can find the cumulative sum of values and add the constant to the Output.For Example, if we have a vector called X and we want to add values in X in sequence to the previous value with ... Read More

Create cross tabulation for three categorical columns in an R data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 10:00:04

1K+ Views

To create cross tabulation for three categorical columns, we can use xtabs function. The xtabs function will create contingency table for each category in two columns and each contingency table will be created for the category in the third column.Check out the below Examples to understand how it can be ... Read More

R Programing to change the name of column variable and row variable in xtab table.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 09:44:48

320 Views

To change the name of column variable and row variable in xtab table, we can use setNames function.For Example, if we have a xtab table called XTAB and we want to change the column variable name C and row variable name R then we can use the below command −dimnames(XTAB)Read More

How to create confusion matrix for a rpart model in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 02-Nov-2021 08:37:32

1K+ Views

To create confusion matrix for a rpart model, we first need to find the predicted values then the table of predicted values and the response variable in the original data can be created, which will be the confusion matrix for the model.For Example, if we have a vector of predicted ... Read More

Advertisements