Nizamuddin Siddiqui has Published 2307 Articles

How to extract data.table columns using a vector of column numbers in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:30:26

569 Views

When we have large number of columns and only few of them are useful for analysis then extraction of such columns becomes helpful.If we have a vector that contains column numbers and we want to extract the columns from a data.table object then we can use the single square brackets ... Read More

How to divide all columns by one column and keeping original data in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:25:12

3K+ Views

To divide all columns of data frame in R by one column and keeping the original data, we can use mutate_at function of dplyr package along with list function.For example, if we have a data frame called df that contains five columns say x, y, z, a, and b then ... Read More

Create histogram with horizontal boxplot on top in base R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:23:20

613 Views

To create a histogram with horizontal boxplot on top in base R, we first need to define the layout of the plotting area with layout function and par function margin (mar) then the boxplot will be created and after that the histogram will be created. While creating the boxplot and ... Read More

How to increase the width of lines for histogram like plots in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:17:39

378 Views

The histogram like plot in base R is the plots of vertical lines instead of points in a vector or column of a data frame. If we increase the width of these lines then the plot becomes more like a histogram as the increment in widths make the vertical lines ... Read More

How to change the border style of a circle in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:17:23

163 Views

We can create a circle in R by using draw.circle function of plotrix package and default border will be like straight lines. If we want to change the border style of a circle then we can use lty argument and set it to different values as shown in the below ... Read More

How to increase the X-axis labels font size using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:15:31

26K+ Views

To increase the X-axis labels font size using ggplot2, we can use axis.text.x argument of theme function where we can define the text size for axis element. This might be required when we want viewers to critically examine the X-axis labels and especially in situations when we change the scale ... Read More

How to create a group column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:13:42

768 Views

Suppose we have a data frame called df that contains two columns say X and Y then we can create a group column based on X and Y by converting df into a data.table object and creating list of values in X and Y with list function.Check out the below ... Read More

How to multiply two matrices in R if they contain missing values?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 07:04:41

628 Views

If we want to multiply two matrices if they contain missing values then we first need to convert the missing values to zeros and then the multiplication can be easily done. If we do not do so then the Output of the multiplication will have NAs at all positions.Check out ... Read More

How to hide outliers in base R boxplot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 06:54:45

244 Views

To hide outliers in base R boxplot, we can use range argument inside boxplot function but we will have to play with range argument. The range argument can take many values therefore, we would need to find the correct one that removes all the outliers. To understand how it works ... Read More

Create darker gridlines in theme_bw for a ggplot2 graph in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Nov-2021 06:47:02

909 Views

To create darker gridlines in theme_bw for a ggplot2 graph, we can use theme function, where we can use major and minor gridlines element line to black color with the help of panel.grid.major and panel.grid.minor argument as shown in the below Example.We can use any other color but black is ... Read More

Advertisements