Programming Articles

Page 2273 of 2547

How to create a predictive linear regression line for a range of independent variable in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 372 Views

If we want to create a regression line inside scatterplot then lines function can be used with the linear model function lm but if we want to do it for a particular range of independent variable then this range needs to be defined and passed within the lines function. Check out the below example of linear regression model that considers a range of independent variable for prediction.Consider the below vectors −Examplestrsplit(x6,"[*]")OutputDefining the range of x −Range_of_x

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 423 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 not be able to convert the data.object to a matrix. For example, if we have a data.table object DT then to convert it into a matrix, we should use the below example code −DT_matrix

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 244 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 lwd = 0 is the default value for the width.Consider the below vector and create the line chart −Examplex

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 195 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 the help of lwd argument.Consider the below vector and create the very wide line chart to cover the plot area −Examplex

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Oct-2020 404 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 for four categories as 0.25 each then each bar will be of equal width and if they vary as 0.30, 0.40, 0.20, 0.45 then the width of the bars will be different based on these widths.Consider the below vector x and the corresponding width vector −x

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 945 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 different categories and create the boxplot for these categories −ExampleClass1

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 365 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. This will help us to understand the distribution of the values in whole data set that lies above or below certain value. For this purpose, we can simply use hist function with col argument to change the color of the values that are greater than or less than a fixed ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Oct-2020 6K+ 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.Examplex1

Read More

How to add a mathematical expression in axis label in a plot created by using plot function in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Oct-2020 697 Views

When we create a plot using plot function in R, the axes titles are either chosen by R automatically based on the vectors passed through the function or we can use ylab or xlab for particular axes. To add a mathematical expression in an axis label, we can use title function with expression function to define the mathematical expression.Consider the below vectors and create scatterplot between the two −Exampleset.seed(111) x

Read More

How to create a black and white word cloud in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Oct-2020 251 Views

According to Google, a word cloud is an image composed of words used in a particular text or subject, in which the size of each word indicates its frequency or importance. In R, we can create word cloud by using wordcloud function of wordcloud package. So, we have the same name of the function as the package, thus we should not get confused by it.Loading wordcloud package and creating a wordcloud −library("wordcloud") x

Read More
Showing 22721–22730 of 25,466 articles
Advertisements