Nizamuddin Siddiqui has Published 2307 Articles

How to display raise to the power on X-axis in base R plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:25:13

294 Views

To display anything different than the vector or column names on the axes, we need to use xlab for X-axis and ylab for Y-axis. Therefore, if we want to display raise to the power on X-axis then xlab argument will be along with the plot function. For example, if we ... Read More

How to create bar plot with log values using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:23:39

965 Views

To create the bar plot using ggplot2, we simply need to use geom_bar function and if we want to have the log scale of y variable then it can be set with aes under geom_bar. For example, if we have a data frame called df that contains a categorical column ... Read More

How to find the significant correlation in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:23:21

460 Views

To find the significant correlation in an R data frame, we would need to find the matrix of p-values for the correlation test. This can be done by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called ... Read More

How to get the colour name from colour code in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:22:31

440 Views

To get the color name from color code, we can use the color_id function of plotrix package. If we have a vector of colour codes say x then the colour name can be found by using the command sapply(x, color.id).ExampleLive Demo> x xOutput[1] "#FF0000" "#FF1F00" "#FF3D00" "#FF5C00" "#FF7A00" "#FF9900" "#FFB800" ... Read More

How to extract unique combination of rows in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:20:12

659 Views

To extract the unique combination of rows, we can subset the data frame with single square brackets and use the negation of the duplicated function after sorting the rows in the data frame. The sorting of the data frame can be done with the help of apply function and we ... Read More

How to find the row sum for each column by row name in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:19:52

2K+ Views

To find the row sum for each column by row name, we can use rowsum function. For example, if we have a matrix called M then the row sums for each column with row names can be calculated by using the command rowsum(M, row.names(M)).Example1Live Demo> M1 rownames(M1) colnames(M1) M1Output    ... Read More

How to change the legend title in ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:19:33

370 Views

In ggplot2, by default the legend title is the title of the grouping column of the data frame. If we want to change that title then scale_color_discrete function. For example, if we have a data frame called df that contains two numerical columns x and y and one grouping column ... Read More

How to convert a data frame into table for two factor columns and one numeric column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:15:52

374 Views

When we have two factor columns and one numeric column then we can create a contingency table for the total count of numeric values based on the factor columns. This can be done with the help of xtabs function in base R. For example, if we have a data frame ... Read More

How to create group names for consecutively duplicate values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:12:19

341 Views

The grouping of values can be done in many ways and one such way is if we have duplicate values or unique values then the group can be set based on that. If all the values are unique then there is no sense for grouping but if we have varying ... Read More

How to find the row-wise mode of a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Mar-2021 06:11:00

452 Views

There is no in-built function to find the mode in R, hence we need to create one and then apply it to the rows of the matrix. The function for mode is created as follows −mode M1 M1Output     [, 1] [, 2] [, 3] [, 4] [, 5] [1, ... Read More

Advertisements