Nizamuddin Siddiqui has Published 2307 Articles

How to convert data.table object into a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 13:54:16

228 Views

A data.table object is very similar to a data frame in R, therefore, converting a data.table object to a matrix is not a difficult job. We just need to use as.matrix function and store the data.table object into a new object that will belong to the matrix, otherwise R will ... Read More

How to deal with warning message “Removed X rows containing missing values” for a column of an R data frame while creating a plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 13:47:16

725 Views

If we have missing values/NA in our data frame and create a plot using ggplot2 without excluding those missing values then we get the warning “Removed X rows containing missing values”, here X will be the number of rows for the column that contain NA values. But the plot will ... Read More

How to visualize two categorical variables together in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 13:44:32

5K+ Views

The categorical variables can be easily visualized with the help of mosaic plot. In a mosaic plot, we can have one or more categorical variables and the plot is created based on the frequency of each category in the variables. To create a mosaic plot in base R, we can ... Read More

How to create a line chart in R using plot function with larger width?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 15:06:04

127 Views

To create a line chart in base R using plot function, we need to use type = "l" so that R understand the plot needs to have a line instead of points. If we want to increase the width of the line then lwd argument can be used. The value ... Read More

How to create a chart by covering the area of the plot from bottom left to upper right in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 14:39:29

47 Views

The plot area in plot window is fixed by default and we can create a lint chart with extended width so that the chart covers the area of the plot from bottom left to upper right. This can be done by using very large width of the line chart with ... Read More

How to create varying width bar chart using barplot function in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 12:17:16

234 Views

The barplot function create the bars of equal width but if we have equal or unequal width values for each bar then we can use width within the barplot function. Thus, the newly generated barplot will have different width of the bars. For example, if we the width are defined ... Read More

How to change the X-axis labels for boxplots created by using boxplot function in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 12:14:30

719 Views

When we create boxplots for multiple categories in R using boxplot function, by default the X-axis labels are represented by numbers. But we might want to express the categories by their name. In this situation, we can use names argument along with the boxplot function.Consider the below vectors that represent ... Read More

How to change the color of bars in histogram for values that are greater than 0 or less than 0 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 12:11:11

192 Views

Although, the histogram represents the distribution of a complete set of values but we might want to visualize that histogram based on the division of some threshold value. For example, we might want to visualize the histogram with different bars that have values greater than 1 or less than 1. ... Read More

How to find residual variance of a linear regression model in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 12:08:54

5K+ Views

The residual variance is the variance of the values that are calculated by finding the distance between regression line and the actual points, this distance is actually called the residual. Suppose we have a linear regression model named as Model then finding the residual variance can be done as (summary(Model)$sigma)**2.Examplex1Read More

How to display the values of two columns of an R data frame separately in a plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 12:03:50

879 Views

In general, the scatterplot is used to visualize the relationship between two columns of an R data frame but if we want to display the two columns separately not as a pair then we need to use matplot function. This function will create a plot for all the values in ... Read More

Advertisements